Chapter 9 - Fatal error: Unexpectedly found nil while unwrapping an Optional value

Input: xcode 12.0. UIKIt Apprentice First Edition
I finished a few steps on Chapter 9 where override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) → UITableViewCell {} were update with

 let cell = tableView.dequeueReusableCell(
   withIdentifier: "ChecklistItem", 
   for: indexPath)

 // Add the following code
 let label = cell.viewWithTag(1000) as! UILabel

When I run my code I got an error message : Checklists/ChecklistViewController.swift:32: Fatal error: Unexpectedly found nil while unwrapping an Optional value
2022-02-11 16:47:52.706024+0100 Checklists[11880:1475402] Checklists/ChecklistViewController.swift:32: Fatal error: Unexpectedly found nil while unwrapping an Optional value
But I’m bot sure how to unwrap the label variable correctly. How is it possible to solve?

Generally, this happens if you didn’t get the table cell when you dequeued it or if you set the tag for the incorrectly for the label. So check that you set the cell identifier correctly and/or that you set the tag correctly and saved the tag value.

If both of the above are correct and the issue still persists, then please upload a ZIP archive of your project so that I (or somebody else) can take a look at the project to see what is going on.

1 Like

Thanks, Fahim! Yes, the problem was with the Identifier. I used number 100 instead of 1000 and that’s why it failed.