.removeAll()

KyraThompson's avatar
Published Apr 26, 2023Updated May 5, 2023
Contribute to Docs

The .removeAll() method will remove all key-value pairs from a dictionary.

Syntax

dictionaryInstance.removeAll()

Note: The .removeAll() method takes no parameters.

Example

var bookShelf = [
"Moby Dick": "Herman Melville",
"The Odyssey": "Homer",
"Pride and Prejudice": "Jane Austen"
]
bookShelf.removeAll()
print(bookShelf)

In the example above, all key-value pairs in the bookShelf dictionary are removed. This will output an empty dictionary:

[:]

All contributors

Contribute to Docs

Learn Swift on Codecademy