美文网首页
isMemberOfClass和isKindOfClass区别

isMemberOfClass和isKindOfClass区别

作者: coding_Liu | 来源:发表于2019-06-22 16:31 被阅读0次
    if ([scrollView isKindOfClass:[UIView class]]) {
        NSLog(@"scrollView is isKindOfClass UIView");
    }
    
    if ([scrollView isKindOfClass:[UIScrollView class]]) {
        NSLog(@"scrollView is isKindOfClass UIScrollView");
    }
    
    if ([scrollView isMemberOfClass:[UIView class]]) {
        NSLog(@"scrollView is isMemberOfClass UIView");
    }
    
    if ([scrollView isMemberOfClass:[UIScrollView class]]) {
        NSLog(@"scrollView isMemberOfClass UIScrollView");
    }
    

    输出结果:
    scrollView is isKindOfClass UIView
    scrollView is isKindOfClass UIScrollView
    scrollView isMemberOfClass UIScrollView

    结论:
    isMemberOfClass 用于判断(实例对象)和(对象的创建类)
    isKindOfClass 用于判断(实例对象)和(对象的创建类或继承的类)

    相关文章

      网友评论

          本文标题:isMemberOfClass和isKindOfClass区别

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