Optionals: Implicitly Unwrapped Optionals
Are useful when an optional’s value is confirmed to exist immediately after the optional is first defined and can definitely be assumed to exist at every point thereafter. .
Let possibleString: String? = "An optional string."
let forcedString: String = possibleString! // requires an exclamation mark Let assumedString: String! = "An implicitly unwrapped optional string."
let implicitString: String = assumedString // no need for an exclamation mark If assumedString != nil {
print(assumedString!)
}
// Prints "An implicitly unwrapped optional string." If let definiteString = assumedString {
print(definiteString)
}
// Prints "An implicitly unwrapped optional string." Optional will always have a value, after that value is first set.
Is a normal optional behind the scenes, but can also be used like a nonoptional value, without the need to unwrap the optional value each time it’s accessed.
Semantic portal