我有以下代码:
NSString *content = [[NSUserDefaults standardUserDefaults] stringForKey:@"mykey"];
NSLog(@"string is %@",content);
if ([content stringIsEmpty]){
NSLog(@"empty string");
}else{
NSLog(@"string is not empty");
}
stringIsEmpty 是类类别NSString
:
- (BOOL ) stringIsEmpty {
if ((NSNull *) self == [NSNull null]) {
return YES;
}
if (self == nil) {
return YES;
} else if ([self length] == 0) {
return YES;
}
return NO;
}
输出是:
string is (null)
string is not empty
它怎么可能同时为空而不为空?