I was wondering what this code does:
var something: String = "Hi"
if something = "Hello world!" {
// Will this be executed?
}
Will it assign to something
variable and do the if
body? Or will it set the value of that variable only for the if
body and outside it will not change? Or has it anything to do with nil
?
This pattern only works for assignments that can fail — that is, if you're assigning the result of an expression that returns an Optional value. And in that case, you use
if let
, not justif
.