美文网首页
OC 判断对象是否为空

OC 判断对象是否为空

作者: LovelyYilia | 来源:发表于2021-04-24 13:42 被阅读0次

判断对象是否为空

+ (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;
}

相关文章

网友评论

      本文标题:OC 判断对象是否为空

      本文链接:https://www.haomeiwen.com/subject/cnzkrltx.html