-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Learning Swift Second Edition
By :

There is a second type of optional called an implicitly unwrapped optional. There are really two ways to look at what an implicitly unwrapped optional is; one way is to say that it is a normal variable that can also be nil; the other way is to say that it is an optional that you don't have to unwrap to use. The important thing to understand about them is that, similar to optionals, they can be nil, but you do not have to unwrap them like a normal variable.
You can define an implicitly unwrapped optional with an exclamation mark (!
) instead of a question mark (?
) after the type name:
var name: String!
Similar to regular optionals, implicitly unwrapped optionals do not need to be given an initial value because they are nil by default.
At first it may sound like it is the best of both worlds, but in reality it is more like the worst of both worlds. Even though an implicitly unwrapped optional does not have to be unwrapped, it will crash your entire program if it is...
Change the font size
Change margin width
Change background colour