cyclingIsBetter
cyclingIsBetter

Reputation: 17591

IOS: add an object in a specific position of a NSMutableArray

In my project I want to add an object in a specific position of a NSMutableArray, example:

if(index ==1) {
// I want add object at position 1 of NSMutableArray
}

if(index == 2) {
// I want add object at position 2 of NSMutableArray
}
...
if(index == 15) {
// I want add object at position 15 of NSMutableArray
}

How can I do?

Upvotes: 1

Views: 16386

Answers (2)

extremeboredom
extremeboredom

Reputation: 1502

use [array insertObject:object atIndex:index];

Upvotes: 23

kubi
kubi

Reputation: 49354

You could use a C array for this.

id objects[15];

objects[index] = yourObject;

Upvotes: 0

Related Questions