How to check object is nil or not in swift?

后端 未结 11 1941
借酒劲吻你
借酒劲吻你 2020-12-30 18:33

Suppose I have String like :

var abc : NSString = \"ABC\"

and I want to check that it is nil or not and for that I try :

if         


        
11条回答
  •  醉梦人生
    2020-12-30 19:17

    if (MyUnknownClassOrType is nil) {
        println("No class or object to see here")
    }
    

    Apple also recommends that you use this to check for depreciated and removed classes from previous frameworks.

    Here's an exact quote from a developer at Apple:

    Yes. If the currently running OS doesn’t implement the class then the class method will return nil.

    Hope this helps :)

提交回复
热议问题