NSMutableArray removeObjectAtIndex

If I have an NSMutableArray with 10 objects

I run this line of code

[tempArray removeObjectAtIndex:0];

then

[tempArray count] should return 9

but the whole array moves up

The object in index 1 goes to index 0
The object in index 2 goes to index 1
...
The object in index 9 moves to index 8

or index 0 = nil?

+5
source share
3 answers

In the NSMutableArray Documentation :

To fill the gap, all elements outside the index are moved by subtracting 1 from their index.

+7
source

1 . 0 , 1 ..

+2

removeObjectAtIndex

insertObjectAtIndex

addObject adds an object to the end, so there is no offset

0
source

All Articles