How to check object is nil or not in swift?

后端 未结 11 2068
借酒劲吻你
借酒劲吻你 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:28

    Swift short expression:

    var abc = "string"
    abc != nil ? doWork(abc) : ()
    

    or:

    abc == nil ? () : abc = "string"
    

    or both:

    abc != nil ? doWork(abc) : abc = "string"
    

提交回复
热议问题