5

If I have an NSMutableArray with 10 objects

I run this line of code

[tempArray removeObjectAtIndex:0];

then

[tempArray count] should return 9

but does the entire Array shift up

Object At Index 1 moves to Index 0
Object at Index 2 moves to Index 1
...
Object at Index 9 moves to Index 8

or is Index 0 = nil?

3 Answers 3

7

From the NSMutableArray documentation:

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

Sign up to request clarification or add additional context in comments.

1 Comment

right but is this done by iOS or do we have to manually make a method to do this? (Sorry for the dumb question).
2

The array will shift all of the objects down 1 from the right of the removed index. Index 0 will be what was at index 1 and so forth.

Comments

0

removeObjectAtIndex shifts indexes down

insertObjectAtIndex shifts indexed up

addObject adds object at the end so there is no shifting

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.