Increased Safety in Swift 3
Things are different with Swift 3.0. The
!
ininit!
indicates that the initialization process can fail, and if it doesn’t, that the resulting instance may be forced (i.e., implicitly unwrapped). Unlike in Swift 2.x, instances resulting frominit!
areOptional
s and notImplicitlyUnwrappedOptional
s. That means you will have to employ optional binding or chaining to access the underlying value.[…]
We never explicitly declared that
nilPerson
should be anImplicitlyUnwrappedOptional
. And it’s not great that the compiler inferred unsafe type information.Swift 3.0 solves this problem by treating
ImplicitlyUnwrappedOptional
s asOptional
unless we explicitly declare that we want anImplicitlyUnwrappedOptional
.