-
-
Save anonymous/15bdaeab9a69f4ffcb2b3d8e16a1a342 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.foodType | |
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
Hi there, great tut so far but I think there is a small error on line 8. It should be
// 2
let foodType = foodItem.type