How to check object is nil or not in swift?

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

    Swift-5 Very Simple Way

    //MARK:- In my case i have an array so i am checking the object in this
        for object in yourArray {
            if object is NSNull {
                print("Hey, it's null!")
    
            }else if object is String {
                print("Hey, it's String!")
    
            }else if object is Int {
                print("Hey, it's Int!")
    
            }else if object is yourChoice {
                print("Hey, it's yourChoice!")
    
            }
            else {
                print("It's not null, not String, not yourChoice it's \(object)")
            }
        }
    

提交回复
热议问题