<!--
{
  "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/append(addingCount:initializingWith:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s11UniqueArrayVsRi_zrlE6append11addingCount16initializingWithySi_ys10OutputSpanVyxGzqd__YKXEtqd__YKs5ErrorRd__lF"
  },
  "title" : "append(addingCount:initializingWith:)"
}
-->

# append(addingCount:initializingWith:)

Append a given number of items to the end of this array by populating
an output span.

```
mutating func append<E>(addingCount newItemCount: Int, initializingWith initializer: @_lifetime(0: copy 0) (inout OutputSpan<Element>) throws(E) -> Void) throws(E) where E : Error
```

## Parameters

`newItemCount`

The number of items to append to the array.

`initializer`

A callback that gets called at most once to directly
populate newly reserved storage within the array. The function
is allowed to initialize fewer than `uninitializedCount` items.
The array is appended however many items the callback adds to the
output span before it returns (or before it throws an error).

## Discussion

If the array does not have sufficient capacity to hold the requested
number of new elements, then this reallocates the array’s storage to
grow its capacity, using a geometric growth rate.

If the callback fails to fully populate its output span or if
it throws an error, then the array keeps all items that were
successfully initialized before the callback terminated the insertion.

> Complexity: O(`uninitializedCount`)

---

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)