OC 判断对象是否为空
2021-04-24 本文已影响0人
LovelyYilia
判断对象
是否为空
+ (BOOL)isBlankObject:(__kindof id)object {
if (!object) {
return YES;
}
if (object == NULL) {
return YES;
}
if ([object isEqual:[NSNull null]]) {
return YES;
}
if ([object respondsToSelector:@selector(length)]) {
NSUInteger count = (NSUInteger)[object performSelector:@selector(length)];
return count == 0;
}
///集合类型
if ([object respondsToSelector:@selector(count)]) {
NSUInteger count = (NSUInteger)[object performSelector:@selector(count)];
return count == 0;
}
return NO;
}