Check empty string in Swift?

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

    To do the nil check and length simultaneously Swift 2.0 and iOS 9 onwards you could use

    if(yourString?.characters.count > 0){}
    

提交回复
热议问题