Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSPredicate check for kind of object class

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

How to code predicate with "isKindOf:"?

like image 561
user500 Avatar asked Nov 09 '11 13:11

user500


2 Answers

Try (depracated)

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

Or

[NSPredicate predicateWithFormat: @"class == %@", [someObject class]]
like image 123
Jef Avatar answered Oct 14 '22 00:10

Jef


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

like image 30
zekel Avatar answered Oct 14 '22 00:10

zekel