字符串 为空判断

Swift 字符串 为空判断 并返回字符串

func emptyString(_ str :AnyObject)-> String
{
var string = str

    var isNO:Bool!
    isNO = false
    if ((string as AnyObject).isEqual(String.init()))
    {
        isNO = true
    }
    else if ((string as AnyObject).isEqual(NSNull.init()))
    {
        
        isNO = true
    }
        
    else if (string as! String == "\("")")
    {
        isNO = true
    }
    else if (string as! String == "\("null")")
    {
        isNO = true
    }
    else if (string as! String == "\("(null)")")
    {
        isNO = true
    }
    else if (string as! String == "\("")")
    {
        isNO = true
    }
    else if (string.isEmpty)
    {
        isNO = true
    }
        
    else if (string.length == 0)
    {
        isNO = true
    }
    else
    {
        isNO = false
    }
    
    if (isNO == true) {
        string = "" as AnyObject as AnyObject
    }
    
    return string as! String
}

你可能感兴趣的:(字符串 为空判断)