.removeAll()

The .removeAll() method is used to remove every value from a Set in Swift.

Syntax

setName.removeAll()
  • .removeAll() will remove all values from setName.
  • It is not possible to use a (where:) condition on a set because Set does not currently conform to the RangeReplaceableCollection 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:

[]

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Swift on Codecademy

Contributors