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 ...

Get Cocoa in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.