NSPredicate check for kind of object class

前端 未结 3 1486
梦如初夏
梦如初夏 2020-12-09 08:46

I have an array of UIView objects. I want to call - (NSArray *)filteredArrayUsingPredicate:(NSPredicate *)predicate on this array to get array of <

相关标签:
3条回答
  • 2020-12-09 09:13

    I got errors using Jef's method. This worked for me, though.

    NSPredicate *predicate = [NSPredicate predicateWithFormat:
                                                  @"self isKindOfClass: %@", class];
    

    Source: https://stackoverflow.com/a/2556306/168594

    0 讨论(0)
  • 2020-12-09 09:24

    How about using -className as your key?

    NSPredicate* foo = [NSPredicate predicateWithFormat: @"className == %@", @"MyCustomView"];
    
    0 讨论(0)
  • 2020-12-09 09:29

    Try (depracated)

    [NSPredicate predicateWithFormat: @"className == %@", [someObject className]]
    

    Or

    [NSPredicate predicateWithFormat: @"class == %@", [someObject class]]
    
    0 讨论(0)
提交回复
热议问题