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.