Inserts a new element at the specified position.
SDK
- Xcode 10.2+
Framework
- Swift Standard Library
Declaration
Parameters
newElement
The new element to insert into the array.
i
The position at which to insert the new element.
index
must be a valid index of the array or equal to itsend
property.Index
Discussion
The new element is inserted before the element currently at the specified index. If you pass the array’s end
property as the index
parameter, the new element is appended to the array.
Complexity: O(n), where n is the length of the array. If i == end
, this method is equivalent to append(_:)
.