Book Image

Mastering Swift

By : Jon Hoffman
Book Image

Mastering Swift

By: Jon Hoffman

Overview of this book

Table of Contents (22 chapters)
Mastering Swift
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Summary


While the concept of optional types as used in the Swift language might seem a little foreign at first, the more you use them, the more they will make sense. One of the biggest advantages with optional types is, we get additional compile time checks that alert us if we forget to initialize non-optionals prior to using them.

The one thing to take away from this chapter is the concept of what Optionals are. To reinforce this concept, let's review a couple of paragraphs from earlier in this chapter.

It is very important to understand that nil in Swift is very different than nil in Objective-C. In Objective-C, nil is a pointer to a nonexistent object however in Swift nil is an absence of a value. This concept is very important to fully understand Optionals in Swift.

A variable defined as an Optional can contain a valid value or it can be absent of a value. We set a variable to a valueless state by assigning it Swift's special nil value. Optionals of any type can be set to nil, where as...