node ninja
node ninja

Reputation: 32986

How to check if an object exists in an NSMutableArray

Is there a method, like containsObject: for NSMUtableArrays 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?

Upvotes: 1

Views: 1960

Answers (2)

mipadi
mipadi

Reputation: 410592

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.

Upvotes: 4

James Huddleston
James Huddleston

Reputation: 8448

NSMutableArray inherits from NSArray, so all of the NSArray methods work for NSMutableArray.

Upvotes: 12

Related Questions