---
title: "removeAll(keepingCapacity:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/dictionary/removeall(keepingcapacity:)"
---

# removeAll(keepingCapacity:)

Removes all key-value pairs from the dictionary.

## Declaration

```swift
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

Discussion Calling this method invalidates all indices with respect to the dictionary. note: O(n), where n is the number of key-value pairs in the dictionary.

## See Also

### Removing Keys and Values

- [filter(_:)](swift/dictionary/filter(_:).md)
- [removeValue(forKey:)](swift/dictionary/removevalue(forkey:).md)
- [remove(at:)](swift/dictionary/remove(at:).md)
