Fatal Error Unexpectedly found nil when unwrapping an Optional value

I finished Checklist: Chapter 18, and tried to run the app. When I clicked the list to enter the list detail, it crashed.
Why the checklist is nil?

As the code above indicates, checklist is a force-unwrapped optional. You need to actually populate the checklist variable with a value before the ChecklistViewController is displayed. This probably happens in the parent view controller which initiated the display of ChecklistViewController. So check your relevant code there.

One thing you can do is check your project against the provided final project in the book if you want to troubleshoot the issue yourself.

Alternatively, please upload your project as a ZIP file somewhere and provide a link to the ZIP file so that I (or someone else) can download the file and see what might be going on.

I have been trying to check my code against the provided, thanks for your reply. Here is my project.
Checklists.zip (49.4 KB)

In Chapter 16, page 363 you first add the code for handling a tap on the main list of Checklists. That is the code which handles the showing of the screen which crashes for you …

On page 371, you have the following code to be added to AllListsViewController.swift:

override func tableView(_ tableView: UITableView,
           didSelectRowAt indexPath: IndexPath) {
  let checklist = lists[indexPath.row]
  performSegue(withIdentifier: "ShowChecklist",

That was the initial code to display a Checklist. However, that changes again when you add a data model in Chapter 17. In Chapter 18 page 416, you are supposed to add the following line to the above method but leave the existing code as is:

dataModel.indexOfSelectedChecklist = indexPath.row

However, your changes seem to have been a bit different and that is why your code crashes :slight_smile: I am not going to just tell you what you need to do since that is probably not going to help you figure things out. But hopefully, given the above clues, you can figure things out…

Please let me know if you run into any issues.

Then on page

Please compare that to your code.

THANK YOU SO MUCH! I’ve figured it out. When I find out the problem, I realize that it is an embarrassing question to ask. Anyway, thank you again!!!

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