Swift编程语言提到使用isEmpty来检查空字符串.是否存在检查字符串与""不会产生与使用isEmpty相同的结果的情况?
换一种说法:
if str.isEmpty {
XCTAssert(str == "", "This should be true as well")
}
Run Code Online (Sandbox Code Playgroud)
从文档:
通过检查其布尔值isEmpty属性,确定String值是否为空:
if emptyString.isEmpty {
print("Nothing to see here")
}
Run Code Online (Sandbox Code Playgroud)
空字符串是唯一的空字符串,因此不应该string.isEmpty()返回不返回相同值的情况string == "".当然,他们可能会在不同的时间和记忆中这样做.它们是否使用不同的时间和内存是一个未描述的实现细节,但是isEmpty是检查Swift的首选方法(如文档所述).
| 归档时间: |
|
| 查看次数: |
289 次 |
| 最近记录: |