---
title: UniqueArray
framework: Swift
role: symbol
role_heading: Structure
platforms: [iOS 27.0+, iPadOS 27.0+, Mac Catalyst 27.0+, macOS 27.0+, tvOS 27.0+, visionOS 27.0+, watchOS 27.0+]
path: swift/uniquearray
---

# UniqueArray

A dynamically self-resizing, heap allocated, noncopyable array of potentially noncopyable elements.

## Declaration

```swift
@frozen struct UniqueArray<Element> where Element : ~Copyable
```

## Overview

Overview UniqueArray instances automatically resize their underlying storage as needed to accommodate newly inserted items, using a geometric growth curve. This lets code using UniqueArray avoid having to allocate enough capacity in advance; on the other hand, it makes it difficult to tell when and where such reallocations may happen. For example, appending an element to a UniqueArray has highly variable complexity; often, it runs at a constant cost, but if the operation has to resize storage, then the cost of an individual append suddenly becomes proportional to the size of the whole array. The geometric growth curve allows the cost of such latency spikes to get amortized across repeated invocations, bringing the average cost back to O(1); but the spikes make this construct less suitable for use cases that expect predictable, consistent performance on every operation. Implicit growth also makes it more difficult to predict/analyze the amount of memory an algorithm would need. Developers targeting environments with stringent limits on heap allocations may prefer to avoid using dynamically resizing container types as a matter of policy. The type RigidArray provides a fixed-capacity array variant that caters specifically for these use cases, trading ease-of-use for more consistent/predictable execution. For copyable elements, the copy-on-write Array type is an even more convenient and expressive choice.

## Topics

### Initializers

- [init()](swift/uniquearray/init().md)
- [init(capacity:)](swift/uniquearray/init(capacity:).md)
- [init(capacity:copying:)](swift/uniquearray/init(capacity:copying:)-5tkhn.md)
- [init(capacity:copying:)](swift/uniquearray/init(capacity:copying:)-991h4.md)
- [init(capacity:initializingWith:)](swift/uniquearray/init(capacity:initializingwith:).md)
- [init(minimumCapacity:)](swift/uniquearray/init(minimumcapacity:).md)
- [init(repeating:count:)](swift/uniquearray/init(repeating:count:).md)

### Instance Properties

- [capacity](swift/uniquearray/capacity.md)
- [count](swift/uniquearray/count.md)
- [debugDescription](swift/uniquearray/debugdescription.md)
- [description](swift/uniquearray/description.md)
- [endIndex](swift/uniquearray/endindex.md)
- [freeCapacity](swift/uniquearray/freecapacity.md)
- [indices](swift/uniquearray/indices.md)
- [isEmpty](swift/uniquearray/isempty.md)
- [mutableSpan](swift/uniquearray/mutablespan.md)
- [span](swift/uniquearray/span.md)
- [startIndex](swift/uniquearray/startindex.md)

### Instance Methods

- [append(_:)](swift/uniquearray/append(_:).md)
- [append(addingCount:initializingWith:)](swift/uniquearray/append(addingcount:initializingwith:).md)
- [append(copying:)](swift/uniquearray/append(copying:)-1qhpn.md)
- [append(copying:)](swift/uniquearray/append(copying:)-3aouw.md)
- [append(copying:)](swift/uniquearray/append(copying:)-7ntgb.md)
- [append(copying:)](swift/uniquearray/append(copying:)-90c4t.md)
- [append(moving:)](swift/uniquearray/append(moving:)-71oaj.md)
- [append(moving:)](swift/uniquearray/append(moving:)-9p4vs.md)
- [clone()](swift/uniquearray/clone().md)
- [clone(capacity:)](swift/uniquearray/clone(capacity:).md)
- [distance(from:to:)](swift/uniquearray/distance(from:to:).md)
- [edit(_:)](swift/uniquearray/edit(_:).md)
- [formIndex(_:offsetBy:limitedBy:)](swift/uniquearray/formindex(_:offsetby:limitedby:).md)
- [formIndex(after:)](swift/uniquearray/formindex(after:).md)
- [formIndex(before:)](swift/uniquearray/formindex(before:).md)
- [index(_:offsetBy:)](swift/uniquearray/index(_:offsetby:).md)
- [index(after:)](swift/uniquearray/index(after:).md)
- [index(before:)](swift/uniquearray/index(before:).md)
- [insert(_:at:)](swift/uniquearray/insert(_:at:).md)
- [insert(addingCount:at:initializingWith:)](swift/uniquearray/insert(addingcount:at:initializingwith:).md)
- [insert(copying:at:)](swift/uniquearray/insert(copying:at:)-2g824.md)
- [insert(copying:at:)](swift/uniquearray/insert(copying:at:)-4823q.md)
- [insert(copying:at:)](swift/uniquearray/insert(copying:at:)-6kuy5.md)
- [insert(copying:at:)](swift/uniquearray/insert(copying:at:)-9wt40.md)
- [insert(moving:at:)](swift/uniquearray/insert(moving:at:)-4f2qc.md)
- [insert(moving:at:)](swift/uniquearray/insert(moving:at:)-6d5t1.md)
- [isTriviallyIdentical(to:)](swift/uniquearray/istriviallyidentical(to:).md)
- [popLast()](swift/uniquearray/poplast().md)
- [remove(at:)](swift/uniquearray/remove(at:).md)
- [removeAll()](swift/uniquearray/removeall().md)
- [removeLast()](swift/uniquearray/removelast().md)
- [removeLast(_:)](swift/uniquearray/removelast(_:).md)
- [removeSubrange(_:)](swift/uniquearray/removesubrange(_:)-6hkdt.md)
- [removeSubrange(_:)](swift/uniquearray/removesubrange(_:)-6t21j.md)
- [replaceSubrange(_:addingCount:initializingWith:)](swift/uniquearray/replacesubrange(_:addingcount:initializingwith:).md)
- [replaceSubrange(_:copying:)](swift/uniquearray/replacesubrange(_:copying:)-5cbxf.md)
- [replaceSubrange(_:copying:)](swift/uniquearray/replacesubrange(_:copying:)-70i0j.md)
- [replaceSubrange(_:copying:)](swift/uniquearray/replacesubrange(_:copying:)-7599g.md)
- [replaceSubrange(_:copying:)](swift/uniquearray/replacesubrange(_:copying:)-8tpt1.md)
- [replaceSubrange(_:moving:)](swift/uniquearray/replacesubrange(_:moving:)-4de3f.md)
- [replaceSubrange(_:moving:)](swift/uniquearray/replacesubrange(_:moving:)-6vpdp.md)
- [reserveCapacity(_:)](swift/uniquearray/reservecapacity(_:).md)
- [setCapacity(_:)](swift/uniquearray/setcapacity(_:).md)
- [swapAt(_:_:)](swift/uniquearray/swapat(_:_:).md)

### Subscripts

- [subscript(_:)](swift/uniquearray/subscript(_:).md)

### Type Aliases

- [UniqueArray.Index](swift/uniquearray/index.md)

### Default Implementations

- [Equatable Implementations](swift/uniquearray/equatable-implementations.md)
- [Hashable Implementations](swift/uniquearray/hashable-implementations.md)

## Relationships

### Conforms To

- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Heap Storage

- [UniqueBox](swift/uniquebox.md)
