<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/UniqueArray/insert(copying:at:)-9wt40",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s11UniqueArrayV6insert7copying2atySRyxG_SitF"
  },
  "title" : "insert(copying:at:)"
}
-->

# insert(copying:at:)

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

```
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.

> Complexity: O(`self.count` + `newElements.count`)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)