Objective-c – Add Objects from one Array to Another at a Specific Position

nsmutablearrayobjective c

I have two Mutable Arrays, firstArray and secondArray. Both are populated with objects. I want to add the objects from secondArray to firstArray at a specific point (not at the end and not at the beginning) in the firstArray. Is there a way to do this? Currently I'm only using this line of code:

[self.firstArray addObjectsFromArray:secondArray];

What I want is FOO CODE: self.firstArray addObjectFromArray AT SPECIFIC POINT X: secondArray,specificpointX)

Any help is appreciated!

Best Answer

Answering my own question, this works:

 int z;
 z = (int)self.specificPosition;

 // Start adding at index position z and secondArray has count items

 NSRange range = NSMakeRange(z, [secondArray count]);     
 NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:range];
 [self.firstArray insertObjects:secondArray atIndexes:indexSet];
Related Topic