<!--
{
  "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/Dictionary/removeAll(keepingCapacity:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SD9removeAll15keepingCapacityySb_tF"
  },
  "title" : "removeAll(keepingCapacity:)"
}
-->

# removeAll(keepingCapacity:)

Removes all key-value pairs from the dictionary.

```
mutating func removeAll(keepingCapacity keepCapacity: Bool = false)
```

## Parameters

`keepCapacity`

Whether the dictionary should keep its
underlying buffer. If you pass `true`, the operation preserves the
buffer capacity that the collection has, otherwise the underlying
buffer is released.  The default is `false`.

## Discussion

Calling this method invalidates all indices with respect to the
dictionary.

> Complexity: O(*n*), where *n* is the number of key-value pairs in the
> dictionary.

---

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)