How to deal with "Fatal error: unexpectedly found nil while unwrapping an Optional value."

651 views Asked by At

I'm getting an error

"fatal error: unexpectedly found nil while unwrapping an Optional value".

What should I do?

I have code like this:

var foo: String?
print ("foo = \(foo!)")

And the print statement is crashing with the error "fatal error: unexpectedly found nil while unwrapping an Optional value". What is that, and how do I fix it?

(Note that it's not just print statements that crash. Any time I use foo! to try to get the value of foo, I crash.)

0

There are 0 answers