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

2019-06-09  本文已影响0人  subclass徐

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

上一篇下一篇

猜你喜欢

热点阅读