.remove()
Anonymous contributor
Published Oct 31, 2022
Contribute to Docs
The .remove()
method removes and returns a specified element from a set.
Syntax
setName.remove(at: element)
If the element
parameter exists in setName
, it is removed and returned.
Example
In the example below, The "autumn"
element in the weather
set is removed:
var weather: Set = ["spring", "summer", "autumn", "fall", "winter"]let toRemove = "autumn"if let _ = weather.remove(toRemove) {print(weather)}
This will output the following:
["spring", "summer", "fall", "winter"]
All contributors
- Anonymous contributor
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