Next: 2.9.3 Replacing an Object Up: 2.9 NSMutableArray Previous: 2.9.1 Adding an Object

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