-
-
Save jurgenizer/dac1d2fd0fb035d5b71a3c0077c9de32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) | |
// 1 | |
let foodItem = foodItems[indexPath.row] | |
// 2 | |
let foodType = foodItem.type | |
cell.textLabel?.text = foodType | |
// 3 | |
let foodDate = foodItem.added as! Date | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = "MMMM d yyyy, hh:mm" | |
cell.detailTextLabel?.text = dateFormatter.string(from: foodDate) | |
// 4 | |
if foodType == "Fruit" { | |
cell.imageView?.image = UIImage(named: "Apple") | |
}else{ | |
cell.imageView?.image = UIImage(named: "Salad") | |
} | |
return cell | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Small fix from Brian Avent's tut