Adding an object at a specific index of an NSMutableArray

system picture system · Feb 28, 2011 · Viewed 89.9k times · Source

How can an object be added at a specific index of an NSMutableArray?

How is an object added to the front of the array?

Answer

user142019 picture user142019 · Feb 28, 2011
[myMutableArray insertObject:myObject atIndex:42];

To add an object to the front of the array, use 0 as the index:

[myMutableArray insertObject:myObject atIndex:0];