Debugging a Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file error

I’m getting this error in Chapter 17 of iOS Apprentice 8.3.0. On page 427, it suggests that I can run the app and add items under a checklist. I’m able to add a new checklist, but I get the above error when I click on the “+” for the new checklist item. I suspect that I haven’t initialized some variable so that it isn’t a nil. What I’m really asking here is “how do I debug this?”.

Addendum: The line that blew up was in ItemDetailViewController viewWillAppear:
override func viewWillAppear(_ animated: Bool) {
print("ItemDetailViewController viewWillAppear ")
textField.becomeFirstResponder() <— stopped on this line

Normally console will say what the problem is.

Try commenting out //, the line in your code textField.becomeFirstResponder() and see what error comes up next. Maybe textField doesn’t exist or isn’t linked to the storyboard…

1 Like

One of your objects being unwrapped with ! can’t be unwrapped because + didn’t add it. Compare your code with the sample code folder and see how RW did it.

1 Like

Hi @steveb_la, were you able to resolve this issue? @doyle made a few good points. Generally when you receive the fatal error of finding nil with an optional value it is most likely because somewhere in your code you’re saying that your optional definitely has a value. However, with this error it seems unlikely that it does. The goal would be to pinpoint which optional is causing you trouble and safely unwrapping it to prevent the error.

1 Like

It turns out that the textField in Add Item was not connected to the Outlet.

Thank you all for your support.

1 Like

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