其他分享
首页 > 其他分享> > iOS开发笔记 isKindOfClass和isMemberOfClass的区别

iOS开发笔记 isKindOfClass和isMemberOfClass的区别

作者:互联网

isKindOfClass和isMemberOfClass的区别

底层实现

直接看底层实现:

+ (BOOL)isMemberOfClass:(Class)cls {
    return self->ISA() == cls;
}

- (BOOL)isMemberOfClass:(Class)cls {
    return [self class] == cls;
}

+ (BOOL)isKindOfClass:(Class)cls {
    for (Class tcls = self->ISA(); tcls; tcls = tcls->superclass) {
        if (tcls == cls) return YES;
    }
    return NO;
}

- (BOOL)isKindOfClass:(Class)cls {
    for (Class tcls = [self class]; tcls; tcls = tcls->superclass) {
        if (tcls == cls) return YES;
    }
    return NO;
}

结果总结

对于类对象:

对于实例对象:

标签:tcls,对象,iOS,isMemberOfClass,isKindOfClass,NSObject,class,cls
来源: https://www.cnblogs.com/lwfing/p/16337454.html