本文介绍了在 Swift 中检查空字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Objective C 中,可以执行以下操作来检查字符串:
In Objective C, one could do the following to check for strings:
if ([myString isEqualToString:@""]) {
NSLog(@"myString IS empty!");
} else {
NSLog(@"myString IS NOT empty, it is: %@", myString);
}
如何在 Swift 中检测空字符串?
How does one detect empty strings in Swift?
推荐答案
现在有使用 .isEmpty
检测空字符串的内置功能:
There is now the built in ability to detect empty string with .isEmpty
:
if emptyString.isEmpty {
print("Nothing to see here")
}
Apple 预发布文档:"字符串和字符".
Apple Pre-release documentation: "Strings and Characters".
这篇关于在 Swift 中检查空字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!