How to check object is nil or not in swift?

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

    Swift 4.2

    func isValid(_ object:AnyObject!) -> Bool
    {
        if let _:AnyObject = object
        {
            return true
        }
    
        return false
    }
    

    Usage

    if isValid(selectedPost)
    {
        savePost()
    }
    

提交回复
热议问题