判断对象是否为空(nil、NSNil、@""、@(0) 以上4种)
@interface NSObject (CF)
/**
* 判断对象是否为空
* 常见的:nil、NSNil、@""、@(0) 以上4种返回YES
* 如果需要判断字典与数组,可以自行添加
* @return YES 为空 NO 为实例对象
*/
+ (BOOL)isEmpty:(id)object;
@end
@implementation NSObject (CF)
+ (BOOL)isEmpty:(id)object{
if (object == nil || [object isEqual:[NSNull null]]) {
return YES;
} else if ([object isKindOfClass:[NSString class]]) {
return [object isEqualToString:@""];
} else if ([object isKindOfClass:[NSNumber class]]) {
return [object isEqualToNumber:@(0)];
}
return NO;
}
@end