Instance Method インスタンスメソッド

subtract(_:)

Removes the elements of the given set from this set. 与えられた集合の要素をこの集合から除去します。

Declaration 宣言

mutating func subtract(_ other: Self)

Parameters パラメータ

other

A set of the same type as the current set. 現在の集合と同じ型の集合。

Discussion 議論

In the following example, the elements of the employees set that are also members of the neighbors set are removed. In particular, the names "Bethany" and "Eric" are removed from employees. 次の例において、employees集合の要素でまたneighbors集合のメンバでもあるものは除去されます。個別的には、"Bethany""Eric"employeesから除去されます。


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