Next: NSDictionary Up: NSMutableArray Previous: Removing an Object

Replacing an Object

To replace an object, you can use replaceObjectAtIndex:withObject:, as in
NSMutableArray *array;

array = [NSMutableArray new];
[array addObject: @"Alessia"];
[array addObject: @"Michele"];

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

[array replaceObjectAtIndex: 1  withObject: @"Nicola"];

/* Now the array contains Alessia, Nicola. */
The object which is removed from the array (because it is being replaced) receives a release message; the object which is added to the array (because it replaces the other object) receives a retain message.



Nicola 2002-01-13