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

subtracting(_:)

Returns a new set containing the elements of this set that do not occur in the given set. 与えられた集合の中の現れないこの集合の要素を含んでいる新しい集合を返します。

Declaration 宣言

func subtracting(_ other: Self) -> Self

Return Value 戻り値

A new set. 新しい集合。

Parameters パラメータ

other

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

Discussion 議論

In the following example, the nonNeighbors set is made up of the elements of the employees set that are not elements of neighbors: 次の例において、nonNeighbors集合はemployees集合の要素でneighborsの要素でないものから作り上げられます:


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