views:

84

answers:

2

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?

+11  A: 

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

James Huddleston
awakeFromNib: Worth noting: This is true generally. Unless otherwise stated in a method's documentation, all methods of a class will work on any subclass (or instance of a subclass) of that class. You'll take advantage of this most often with methods of the plist classes (with their mutable versions), NSView, NSControl, NSCell, and, of course, NSObject.
Peter Hosey
+4  A: 

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.

mipadi