Skip to content

Instantly share code, notes, and snippets.

Created March 13, 2017 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/15bdaeab9a69f4ffcb2b3d8e16a1a342 to your computer and use it in GitHub Desktop.
Save anonymous/15bdaeab9a69f4ffcb2b3d8e16a1a342 to your computer and use it in GitHub Desktop.
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
}
@jurgenizer
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment