Check empty string in Swift?

前端 未结 15 1944
臣服心动
臣服心动 2020-11-28 03:51

In Objective C, one could do the following to check for strings:

if ([myString isEqualToString:@\"\"]) {
    NSLog(@\"m         


        
15条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 04:17

    A concise way to check if the string is nil or empty would be:

    var myString: String? = nil
    
    if (myString ?? "").isEmpty {
        print("String is nil or empty")
    }
    

提交回复
热议问题