//Check if we have any search terms in the search dictionary.
if( (strMyString.text==(id) [NSNull null] || [strMyString.text length]==0
|| strMyString.text isEqual:@"")) {
[AlertView showAlert:@"Please enter a valid string"];
}
let myNSString: NSString = ""
if myNSString.length == 0 {
print("String is empty.")
}
或者如果NSString是可选的:
var myOptionalNSString: NSString? = nil
if myOptionalNSString == nil || myOptionalNSString!.length == 0 {
print("String is empty.")
}
// or alternatively...
if let myString = myOptionalNSString {
if myString.length != 0 {
print("String is not empty.")
}
}
正常的SwiftString版本是
let myString: String = ""
if myString.isEmpty {
print("String is empty.")
}