While reading the official Apple Guide I found this
var optionalName: String? = "John Appleseed"
var greeting = "Hello!"
if let name = optionalName {
greeting = "Hello \(name)"
}
There is a constant declaration and assignment where I — as a beginner — expected an expression returning a boolean
. But the condition of this if
statement seems to get true
as the value, because the code inside the parentheses is being executed.
Does the initialization of a constant return a boolean
value or something that a if
statement can use as a condition?
Aucun commentaire:
Enregistrer un commentaire