I was writing a small Category on NSString, and I wanted to know if this method is accurately handles all potential use cases:
Update: to clarify -- I wanted to make sure I'm not missing some oddball case involving character encodings, etc..
@implementation NSString (Helpers)
+(BOOL)stringIsNilOrEmpty:(NSString*)aString {
if (!aString)
return YES;
return [aString isEqualToString:@""];
}
@end
Sample usage:
-(void) sampleUsage {
NSString *emptyString = @"";
NSString *nilString = nil;
NSAssert([NSString stringIsNilOrEmpty:nilString] == YES, @"String is nil/empty");
NSAssert([NSString stringIsNilOrEmpty:emptyString] == YES, @"String is nil/empty");
}
@end
question from:https://stackoverflow.com/questions/14472098/nsstring-nil-or-empty-check-is-this-complete