Why does the following not work in Swift?
if someObject === nil {
}
You have to do the test using the == operator such as
if someO
It works exactly like you expect:
var s: String? = nil
s === nil // true
The only caveat is that to compare to nil
, your variable must able to be nil
. This means that it must be an optional, denoted with a ?
.
var s: String
is not allowed to be nil
, so would therefore always returns false
when ===
compared to nil
.