给NSObject写个分类,方便用
@interface NSObject (additions)
/**
* 判断对象是否为空
* PS:nil、NSNil、@""、@0 以上4种返回YES
*
* @return YES 为空 NO 为实例对象
*/
+ (BOOL)dx_isNullOrNilWithObject:(id)object;
@end
+ (BOOL)dx_isNullOrNilWithObject:(id)object;
{
if (object == nil || [object isEqual:[NSNull null]]) {
return YES;
} else if ([object isKindOfClass:[NSString class]]) {
if ([object isEqualToString:@""]) {
return YES;
} else {
return NO;
}
} else if ([object isKindOfClass:[NSNumber class]]) {
if ([object isEqualToNumber:@0]) {
return YES;
} else {
return NO;
}
}
return NO;
}