insert(_:at:)
Inserts a new element into the array at the specified position.
Declaration
mutating func insert(_ item: consuming Element, at index: Int)Parameters
- item:
The new element to insert into the array.
Discussion
If the array does not have sufficient capacity to hold any more elements, then this reallocates storage to extend its capacity, using a geometric growth rate.
The new element is inserted before the element currently at the specified index. If you pass the array’s endIndex as the index parameter, then the new element is appended to the container.
All existing elements at or following the specified position are moved to make room for the new item.