iOS Apprentice Checklist: fatal error

When I open the source code file 08 - Improved Data Model I get the following error message:

fatal error: unexpectedly found nil while unwrapping an Optional value

This actually happens on all source files in 08, 09, 10.

11 - Local Notifications works fine.

The highlighted code is in DataModel.swift line 42

lists = unarchiver.decodeObjectForKey(“Checklists”) as! [Checklist]

However, that line is the same in 11, but does not throw an error.

Any suggestions?

Does Xcode throw a red or yellow warning on that line? It should if you are using the latest version.

It throws a red one. See attached.

This happens when your Checklists.plist file has different things in it than the code expects. That’s why the tutorial instructs you to remove this file a few times, whenever you add new features to the app. Try removing Checklists.plist, then run the app, add some new to-do items, and go to home screen. The next time you launch the app it should not give the error.

1 Like