.removeAll()
Published Jan 23, 2023
Contribute to Docs
The .removeAll() method is used to remove every value from a Set in Swift.
Syntax
setName.removeAll()
.removeAll()
will remove all values fromsetName
.- It is not possible to use a
(where:)
condition on a set becauseSet
does not currently conform to theRangeReplaceableCollection
protocol that includes that method.
Example
The following is an example of the .removeAll()
method:
var weather: Set = ["spring", "summer", "autumn", "fall", "winter"]weather.removeAll()print(weather)
This will output:
[]
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
- Skill path
Build iOS Apps with SwiftUI
Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.Includes 7 CoursesWith CertificateBeginner Friendly13 hours - Free course
Learn Swift
A powerful programming language developed by Apple for iOS, macOS, and more.Beginner Friendly12 hours