O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8 Optionals

Optionals are a special feature in Swift used to indicate that an instance may not have a value. When you see an optional, you know that one of two things is true about that instance: It either has a value and it is ready for use, or it has no value. If an instance has no value associated with it, we say that it is nil.

You can use optionals with any type to signal that an instance is potentially nil. This feature distinguishes Swift from Objective-C, which only allows objects to be nil.

This chapter covers how to declare optional types, how to use optional binding to check whether an optional is nil and make use of its value if it has one, and how to use optional chaining to query a sequence of optional values. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required