Swift === with nil

前端 未结 2 610
心在旅途
心在旅途 2021-02-13 04:00

Why does the following not work in Swift?

if someObject === nil {
}

You have to do the test using the == operator such as

if someO         


        
2条回答
  •  庸人自扰
    2021-02-13 04:46

    My first instinct would be that nil is not a class instance, but a reference. So someObject cannot be an equivalent class instance to nil.

提交回复
热议问题