---
title: "setCapacity(_:)"
framework: Swift
role: symbol
role_heading: Instance Method
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/setcapacity(_:)"
---

# setCapacity(_:)

Grow or shrink the capacity of a unique array instance without discarding its contents.

## Declaration

```swift
mutating func setCapacity(_ newCapacity: Int)
```

## Parameters

- `newCapacity`: The desired new capacity. newCapacity must be greater than or equal to the current count.

## Discussion

Discussion This operation replaces the array’s storage buffer with a newly allocated buffer of the specified capacity, moving all existing elements to its new storage. The old storage is then deallocated. note: O(count)
