Monday, April 30, 2018

Reimplementation of Implicitly Unwrapped Optionals


The new mental model for IOUs is one where you consider ! to be a synonym for ? with the addition that it adds a flag on the declaration letting the compiler know that the declared value can be implicitly unwrapped.


There are three places where using ! as part of a type is permitted:

  1. Property declarations
  2. Parameters in function declarations
  3. Return values in function declarations


Because implicitly unwrapped optionals are no longer a type distinct from optionals, they can’t be inferred as a type or as any part of a type.


Note that the result of AnyObject lookup is treated as an optional that is implicitly unwrapped. If you lookup a property that itself is also declared as implicitly unwrapped, the expression now has two levels of implicit unwrapping[…] if let and guard let only unwrap a single level of optionality.

Comments RSS · Twitter

Leave a Comment