Bronze Challenge - Ch 10 - ugly solution

hi

i have figured out a way to resolve the bronze challenge (after 2 hours of reflexion…), but my solution seems very ugly to me. I use a static func in ItemCell… which is then called in ItemsVC.
Do you have any tips to improve my code?
thanks

in ItemCell

Blockquote
static func valueLabelColor(label valueLabel: UILabel) {
if let text = valueLabel.text {
if let intValue = Int(text) {
if intValue >= 50 {
valueLabel.textColor = .red
} else {
valueLabel.textColor = .green
}
} else {
valueLabel.textColor = .black
}
} else {
valueLabel.textColor = .black
}
}

Blockquote

In ItemsVC

Blockquote

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) → UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: “ItemCell”, for: indexPath) as! ItemCellTableViewCell
let item = itemStore.allItems[indexPath.row]
cell.nameLabel.text = item.name
cell.serialNumberLabel.text = item.serialNumber
cell.valueLabel.text = “(item.valueInDollars)”
ItemCellTableViewCell.valueLabelColor(label: cell.valueLabel)

Blockquote

In your cellForRowAt function, you can set as follows:

cell.valueLabel.textColor = item.valueInDollars > 50 ? .green : .red

This is the shorthand way of typing:

if item.valueInDollars > 50 {
   cell.valueLabel.textColor = .green
} else {
   cell.valueLabel.textColor = .red
}