<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Set/reserveCapacity(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sh15reserveCapacityyySiF"
  },
  "title" : "reserveCapacity(_:)"
}
-->

# reserveCapacity(_:)

Reserves enough space to store the specified number of elements.

```
mutating func reserveCapacity(_ minimumCapacity: Int)
```

## Parameters

`minimumCapacity`

The requested number of elements to
store.

## Discussion

If you are adding a known number of elements to a set, use this
method to avoid multiple reallocations. This method ensures that the
set has unique, mutable, contiguous storage, with space allocated
for at least the requested number of elements.

Calling the `reserveCapacity(_:)` method on a set with bridged
storage triggers a copy to contiguous storage even if the existing
storage has room to store `minimumCapacity` elements.

---

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)