What is the best way to test if an NSArray contains an object of a certain type of class? containsObject: seems to test for equality, whereas I’m looking for isKindOfClass: equality checking.
What is the best way to test if an NSArray contains an object of
Share
You could use blocks based enumeration to do this as well.
If you have more than one object of this kind of class in your array, you’ll have to tweak the example a bit, but this should give you an idea of what you can do.
An advantage of this over fast enumeration is that it allows you to also return the index of the object. Also if you used
enumerateObjectsWithOptions:usingBlock:you could set options to search this concurrently, so you get threaded enumeration for free, or choose whether to search the array in reverse.The block based API are more flexible. Although they look new and complicated, they are easy to pick up once you start using them – and then you start to see opportunities to use them everywhere.