Instance Method

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

Relationships

From Protocol

See Also

Removing Elements

func filter((Element) -> Bool) -> Set<Element>

Returns a new set containing the elements of the set that satisfy the given predicate.

func removeFirst() -> Element

Removes the first element of the set.

func remove(at: Set<Element>.Index) -> Element

Removes the element at the given index of the set.

func removeAll(keepingCapacity: Bool)

Removes all members from the set.