Implicitly unwrapped optionals

We can define implicitly unwrapped optionals by appending an exclamation mark (!) to the end of the type. These types of optionals will unwrap themselves.

The following example presents two ways to get a value from a dictionary. In the first example, the resulting value will be an optional. The second example will implicitly unwrap the value:

let one = "One" 
let firstValue = dict["One"] 
let implictlyUnwrappedFirstValue: Int! = dict["One"]

Like forcefully unwrapping, implicitly unwrapped Optionals may cause runtime crashes in our applications, so we need to be cautious when we use them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset