Chapter 5. Optionals

An optional differs from a regular variable or constant because it can have two states: It either has some value, or it has no value. When Apple listed the features of their newly announced Swift language, optionals seemed to be one of the concepts that Objective-C developers found the most challenging.

Why? A few possible reasons:

Image The misconception that in Objective-C we already have optional variables—assigning nil to a pointer is possible, and that makes it an optional, right? Wrong!

Image The concept that, for there to be optional ...

Get Swift Translation Guide for Objective-C Users: Develop and Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.