Contents

insert(copying:at:)

Copies the elements of a fully initialized buffer pointer into this array at the specified position.

Declaration

mutating func insert(copying newElements: UnsafeBufferPointer<Element>, at index: Int)

Parameters

  • newElements:

    The new elements to insert into the array. The buffer must be fully initialized.

  • index:

    The position at which to insert the new elements. It must be a valid index of the array.

Discussion

The new elements are inserted before the element currently at the specified index. If you pass the array’s endIndex as the index parameter, then the new elements are appended to the end of the array.

All existing elements at or following the specified position are moved to make room for the new item.

If the array does not have sufficient capacity to hold enough elements, then this reallocates the array’s storage to extend its capacity, using a geometric growth rate.