Removes the specified element from the set.
SDK
- Xcode 6.3+
Framework
- Swift Standard Library
Declaration
@discardableResult mutating func remove(_ member: Element) -> Element?
Parameters
memberThe element to remove from the set.
Return Value
The value of the member parameter if it was a member of the set; otherwise, nil.
Discussion
This example removes the element "sugar" from a set of ingredients.
var ingredients: Set = ["cocoa beans", "sugar", "cocoa butter", "salt"]
let toRemove = "sugar"
if let removed = ingredients.remove(toRemove) {
print("The recipe is now \(removed)-free.")
}
// Prints "The recipe is now sugar-free."