How to check if an object exists in an NSMutableArray
Is there a method, like containsObject: for NSMUtableArrays 开发者_StackOverflow社区to check if an object exists in there without having to loop through the whole array and check each element? What's the best way to check if an object exists in an NSMutableArray?
NSMutableArray
inherits from NSArray
, so all of the NSArray
methods work for NSMutableArray
.
If you're mostly using an array to check if an object exists, and you're using unique elements, you may want to use an NSSet
. Checking a set for membership is faster than checking an array.
精彩评论