Swift keeps throwing errors, can't figure out why

My quick app keeps throwing some fatal errors:

fatal error: unexpectedly found nil while unwrapping an Optional value 

The only problem is that I cannot figure out which line of code is causing this error. Is there a way to see the line of code causing this error?

The project is too large to load, so this seems like the only thing I can do.

Regards, Luca Panjer

+5
source share
2 answers

Xcode should stop the application and display the violation line in the editor with the error EXC_BAD_ACCESS . A comment about restarting Xcode is probably the best first troubleshooting step, as it should happen, regardless of whether you set an exception checkpoint (because it is a fatal failure error, not an exception). You can also try restarting your Mac completely. I had situations where Xcode was just misbehaving until I completely restarted my Mac.

+2
source

If you get this error ...

 unexpectedly found nil while unwrapping an Optional value 

... somewhere in your code, you force the Optional value to be expanded using ! . There is no other reason why this error message will be presented.

One common cause of this error is @IBOutlet declared with ! but incorrectly connected in Interface Builder. I would disconnect and reconnect all @IBOutlet in your project to make sure they are connected correctly.

Other than that, go through each line of code where you use ! to force to expand something and deploy it manually using if let or guard let , or at least set a breakpoint so that you can narrow down, which is forcibly expanded further, causes an error.

There is a reason why ! sometimes called "punch!". It makes things explode. And headaches. A lot of headaches.

0
source

Source: https://habr.com/ru/post/1239512/


All Articles