Here’s a use case for implicitly unwrapped optionals. In any class, all properties have to be initialised upon initialisation of the class instance. You can either assign the properties a default value or use the init
function for property initialisation.
In a view controller, however, you don’t want to use an init
function. Some properties might not have default values but will rather be initialised during viewDidLoad
. In this case you could declare the property as implicitly unwrapped because it won’t be accessed before view controller loading—and after that you can make sure in viewDidLoad
(or in the calling view controller’s prepareForSegue
method, for example) that it is not nil, hence safe to be accessed from now on.
Just my two cents to add to your understanding of IUOs.