SWIFT: Implicitly Wrapped Optionals

Just a quick explanation of how an implicitly wrapped optional can be used. Logically, I would think optional variables are probably more computationally expensive than a normal variable (IMO because it is a fatter object, did not research). So, as far as it goes, it would be best to declare a normal variable in cases where it can not be nil. Then implicitly wrapped variable!, which only uses nil as a fall back. Finally optional variables when something is often nil.

For example String? is basically an special enum Optional

In the examples below, the ? and ! will determine the variable should be accessed.

Leave a Reply

Your email address will not be published. Required fields are marked *