Contents

remove(_:)

Removes the specified element from the set.

Declaration

@discardableResult mutating func remove(_ member: Element) -> Element?

Parameters

  • member:

    The 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."

See Also

Removing Elements