Next: Replacing an Object Up: NSMutableArray Previous: Adding an Object

Removing an Object

To remove an object, you can use removeObjectAtIndex:, as in
NSMutableArray *array;

array = [NSMutableArray new];
[array addObject: @"Michele"];
[array addObject: @"Nicola"];
[array insertObject: @"Alessia" atIndex: 1];

/* Now the array contains Michele, Alessia, Nicola. */

[array removeObjectAtIndex: 0];

/* Now the array contains Alessia, Nicola. */
When an object is removed from the array, it receives a release message. This balances the retain which was sent to the object when it was first added to the array, and allows the object to be deallocated, if needed.



Nicola 2002-01-13