O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

NSMutableArray — Mac OS X 10.0

Synopsis

This class extends the API of NSArray to allow for mutable, ordered collections of objects. NSMutableArray provides five primitive methods, which form the basis for the rest of its methods: addObject:, insertObject:atIndex:, removeLastObject, removeObjectAtIndex:, and replaceObjectAtIndex:withObject:. When an object is added to an array, the array asserts some ownership over the object by sending it a retain message. Likewise, when an object is removed from an array, it is sent a release message by the array.

NSMutableArray is toll-free bridged with the Core Foundation type CFArray. As such, NSMutableArray objects can be used interchangeably with the CFArray pointer type, CFArrayRef.

image with no caption

@interface NSMutableArray : NSArray
                                  // Initializers
   - (id)initWithCapacity:(unsigned)numItems;
                                  // Accessor Methods
   - (void)setArray:(NSArray *)otherArray;
                                  // Class Methods
   + (id)arrayWithCapacity:(unsigned)numItems;
                                  // Instance Methods
   - (void)addObject:(id)anObject;
   - (void)addObjectsFromArray:(NSArray *)otherArray;
   - (void)exchangeObjectAtIndex:(unsigned)idx1 
                                 withObjectAtIndex:(unsigned)idx2;
   - (void)insertObject:(id)anObject 
                                 atIndex:(unsigned)index;
   - (void)removeAllObjects;
   - (void)removeLastObject;
   - (void)removeObject:(id)anObject;
   - (void)removeObject:(id)anObject 
                                 inRange:(NSRange)range;
   - (void)removeObjectAtIndex ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required