Instance Methodswift 6.0.1Swift

    subtract(_:)

    Removes the elements of the given sequence from the set.

    mutating func subtract<S>(_ other: S) where Element == S.Element, S : Sequence

    Parameters

    other

    A sequence of elements. other must be finite.

    In the following example, the elements of the employees set that are also elements of the neighbors array are removed. In particular, the names "Bethany" and "Eric" are removed from employees.

    var employees: Set = ["Alicia", "Bethany", "Chris", "Diana", "Eric"]
    let neighbors = ["Bethany", "Eric", "Forlani", "Greta"]
    employees.subtract(neighbors)
    print(employees)
    // Prints "["Chris", "Diana", "Alicia"]"

    Other members in extension

    Types

    Type members

    Instance members