December 2015
Intermediate to advanced
400 pages
13h 3m
English
Optionals are a mainstay of all nontrivial Swift programs, and the language has a lot of features that make it relatively easy to work with them. Under the hood, however, there is nothing particularly special about the Optional type. It is a generic enum with two cases:
enum Optional<T> {
case None
case Some(T)
}
As you probably expect, the None case corresponds to an optional that is currently nil, and the Some case corresponds to an optional that has a value of type T. Because the Some case is generic, you are able to create optional versions of any type at all.
Most of your interactions with optionals will make use of optional binding and optional chaining, but you can also treat ...
Read now
Unlock full access