Swift .removeAll()
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:
[:]
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Swift on Codecademy
- Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.
- Includes 7 Courses
- With Certificate
- Beginner Friendly.13 hours
- A powerful programming language developed by Apple for iOS, macOS, and more.
- Beginner Friendly.12 hours