ΩlostA
ΩlostA

Reputation: 2601

iOS: String who cannot be nil. How can I do?

Fatal error: unexpectedly found nil while unwrapping an Optional value
I checked that ticket that didn't help me:

What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?

  "CODE_SUPLEMENT7": form.csupplement7! != nil ? form.csupplement7! : "",

I try to avoid that mistake, but it says "Comparing non-optional value of type String to nil always return true."

How to find the good type String with the capability to accept the String ? (because my code is all based on it...)

enter image description here

Thanks in advance.

Upvotes: 1

Views: 56

Answers (1)

rmaddy
rmaddy

Reputation: 318774

Your problem is your use of ! just before the !=.

It should be:

form.csupplement7 != nil ? form.csupplement7! : ""

But even better is to use ??:

form.csupplement7 ?? ""

Upvotes: 2

Related Questions