Chapter 19- Adding the icons to the project

Hello everyone,

i am struggling with chapter 19 - adding the Consulting to the project. i followed steps in the Book iOS Apprentice but when i run the code, it threw this error back

`Error decoding item array: The data couldn’t be read because it is missing.`

, and on the Simulator , there is no icon appeared. Could anyone give me a hint ?
thank you in Advance !

AllListsViewController.swift#######

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { //let cell = makeCell(for: tableView) let cell: UITableViewCell!

    if let c = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) {
        cell = c
    }else {
        cell = UITableViewCell(style: .subtitle, reuseIdentifier: cellIdentifier)
    }
    // Update cell information
    let checklist = dataModel.lists[indexPath.row]
    cell.textLabel!.text = checklist.name
    cell.accessoryType = .detailDisclosureButton
    
    // Access subtitle of label
    cell.detailTextLabel!.text = "\(checklist.countUncheckedItems()) Remaining"
    
    let count = checklist.countUncheckedItems()
    if checklist.items.count == 0 {
        cell.detailTextLabel!.text = "(No items)"
    }else {
        cell.detailTextLabel!.text = count == 0 ? "All done!" : "\(count) Remaining"
    }
    
    cell.imageView!.image = UIImage(named: checklist.iconName)
    return cell
}`

################# Checklist.swift #######################
`import UIKit

class Checklist: NSObject, Codable {
var name = “”
var items = ChecklistItem
var iconName = “”

init(name: String) {
    self.name = name
    super.init()
}
// Counting the unchecked items
func countUncheckedItems() -> Int {
    return items.reduce(0) {cnt, item in cnt + (item.checked ? 0 : 1)}
}

}`

@ganem Can you please help with this when you get a chance? Thank you - much appreciated! :]

@vancouver
I need some more context. Were you able to add the icons to the project?
Looks like you haven’t added the iconName property to Checklist.swift yet.
Where are you stuck exactly?

Please tag me when you reply, so I’ll get a notification when that happens.

This topic was automatically closed after 166 days. New replies are no longer allowed.