[Solved] What happens if array data isn’t present when inserting data at a particular index?


From the NSMutableArray Class Reference on index:

The index in the array at which to insert anObject. This value must not be greater than the count of elements in the array. Important: Raises an NSRangeException if index is greater than the number of elements in the array.

So, in your first example, you’ll get a range exception since 4 > 0.

Continuing…

If index is already occupied, the objects at index and beyond are shifted by adding 1 to their indices to make room.

In your second example, c and d will be shifted over, so your array will be “a, b, c, d”.

In the future, please check the documentation / try first before posting a question.

2

solved What happens if array data isn’t present when inserting data at a particular index?