6.5 Summary
In this chapter, you learned about optionals—a staple of Swift in terms of type safety. It is possible to mark a variable as optional, allowing it to carry nil values. When it comes to accessing an optional, Swift empowers programmers with easy syntax options while preserving safety—such as the nil-coalescing operator, optional binding, and optional chaining.
It is also possible to implicitly unwrap an optional, enforcing the unsafe assumption that it contains a value—but this technique should be avoided whenever possible.
So far, you’ve used variables as data holders. Simple variables, collections, and optionals: All of them hold data but don’t have any behavior. You have mostly used functions to implement behaviors in the program. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access