Check empty string in Swift?

前端 未结 15 1974
臣服心动
臣服心动 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:38

    What about

    if let notEmptyString = optionalString where !notEmptyString.isEmpty {
        // do something with emptyString 
        NSLog("Non-empty string is %@", notEmptyString)
    } else {
        // empty or nil string
        NSLog("Empty or nil string")
    }
    

提交回复
热议问题