Skip to content

Instantly share code, notes, and snippets.

@jurgenizer
Forked from anonymous/cellForRow.swift
Last active June 23, 2017 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jurgenizer/dac1d2fd0fb035d5b71a3c0077c9de32 to your computer and use it in GitHub Desktop.
Save jurgenizer/dac1d2fd0fb035d5b71a3c0077c9de32 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.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
}
@jurgenizer
Copy link
Author

Small fix from Brian Avent's tut

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