hkray
1
// ItemCell.swift
class ItemCell: UITableViewCell {
...
func configure(for item: Item) {
nameLabel.text = item.name
serialNumberLabel.text = item.serialNumber
valueLabel.text = "$\(item.valueInDollars)"
valueLabel.textColor = item.valueInDollars >= 50 ? UIColor.red : UIColor.green
}
}
// ItemsViewController.swift
class ItemsViewController: UITableViewController {
...
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath) as! ItemCell
let item = itemStore.allItems[indexPath.row]
cell.configure(for: item)
return cell
}
}