Every time you force unwrap an Optional
(using !
) a kitten dies.
There are several safe ways of unwrapping an Optional
such as using if let
or flatMap
(even though it's not a real flatMap
).
In several cases you can use Optional Chaining so you don't have to deal with Optional
s before you actually have to. The null coalescing operator (??
) is also pretty useful.
This SO answer is extremely helpful, you should definitely check it out.
If you want to fully understand the concept of Optional
s take a look at the docs.
In that specific case, though, I'd recommend using something like let fetchedName = bowtie.name ?? ""
(or any other fallback string that makes sense for your problem).
When you force unwrap and for some bizarre reason the value is nil
the app will crash. Nobody likes crashes, right?