I had written a NSString
category to judge a string whether an empty string:
- (BOOL)isEmptyString {
if ([self isEqual:[NSNull null]] || self == NULL || self == nil || [self isEqualToString:@""] || self.length == 0)
{
return YES;
}
return NO;
}
However,when a string is a nil string,returned NO
:
NSString *a = nil;
if ([a isEmptyString]) {
NSLog(@"is empty");
} else {
NSLog(@"not empty");
}
Console printed “not empty”.
Why returned NO
?the string is nil so it's meet the condition self == nil
,YES
should been return,isn’t it?