Inserts a given object into the array’s contents at a given index.
- iOS 2.0+
- macOS 10.0+
- UIKit for Mac 13.0+Beta
- tvOS 9.0+
- watchOS 2.0+
The object to add to the array's content. This value must not be
The index in the array at which to insert
an. This value must not be greater than the count of elements in the array.
index is already occupied, the objects at
index and beyond are shifted by adding
1 to their indices to make room.
NSArray objects are not like C arrays. That is, even though you specify a size when you create an array, the specified size is regarded as a “hint”; the actual size of the array is still 0. This means that you cannot insert an object at an index greater than the current count of an array. For example, if an array contains two objects, its size is 2, so you can add objects at indices 0, 1, or 2. Index 3 is illegal and out of bounds; if you try to add an object at index 3 (when the size of the array is 2),
NSMutable raises an exception.