Search code examples
objective-cnsmutablearrayfoundation

Adding an object at a specific index of an NSMutableArray


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

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


Solution

  • [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];