Force Deployment Goal

In the quick documentation you can find this:

if convertedNumber != nil {
    println("convertedNumber has an integer value of \(convertedNumber!).")
}
// prints "convertedNumber has an integer value of 123." 

With this explanation

Once you verify that an option contains a value, you can access its base value by adding an exclamation mark (!) To the end of the option name. The exclamation point effectively says: "I know that this does not necessarily have value, please use it." This is called forced expansion of the option value:

Well, I get it, but what's the use of it? It would not be the same if I did not force to unfold as:

if convertedNumber != nil {
    println("convertedNumber has an integer value of \(convertedNumber).")
}
// prints "convertedNumber has an integer value of 123."

Thank you for enlightening me :)

+4
source share
2 answers

It will not be the same if I did not force to deploy

. - . ( ), .

Optional(123), 123. , , .

, Optionals - , (, " Int", , Int) . , .

+13

if let convertedNumber = <some optional> {
    // If the optional contains a value, then convertedNumber is now the unwrapped value.
    println("convertedNumber has an integer value of \(convertedNumber).")
}
+2

All Articles