What are they for?
In Objective-C, you can safely send a message to
nil, which will return something treated as
0 (this variety is part of the reason Swift has optionals, of which more later). This is a useful and powerful feature, but it only applies to Objective-C objects. There’s no universal way to deal with absent or no-value types such as integers, floats or Booleans. Things like
0 are used to represent “no value” in these cases.
Optionals are Swift’s way of unifying the representation of Nothingness. By using them, we lose some of the ease and flexibility of nil messaging, but gain compile-time checking, safety and a consistent way of dealing with the same problem, regardless of variable type.