iOS开发中用到的判断字符串是否为空的方法

NSString 类别 集成方法为

@interface NSString (Empty)

+ (BOOL)isEmpty:(NSString *)string;

@end

 

@implementation NSString (Empty)

+ (BOOL)isEmpty:(NSString *)string{

 if ([[string class] isSubclassOfClass:[NSNull class]]) { return YES; } if (string == nil || string == NULL || [string isEqualToString:@"(null)"] || [string isEqualToString:@"null"] ||[string isEqualToString:@""]) {

return YES;

}

if ([string isKindOfClass:[NSNull class]]) {

return YES;

}

if ([string isKindOfClass:[NSString class]] && [[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {

return YES;

}

return NO;

}

@end

你可能感兴趣的:(OC)