<!--
{
  "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/RangeReplaceableCollection/reserveCapacity(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sm15reserveCapacityyySiF"
  },
  "title" : "reserveCapacity(_:)"
}
-->

# reserveCapacity(_:)

Prepares the collection to store the specified number of elements, when
doing so is appropriate for the underlying type.

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

## Parameters

`n`

The requested number of elements to store.

## Discussion

If you are adding a known number of elements to a collection, use this
method to avoid multiple reallocations. A type that conforms to
`RangeReplaceableCollection` can choose how to respond when this method
is called. Depending on the type, it may make sense to allocate more or
less storage than requested, or to take no action at all.

---

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)