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

intersection(_:)

Returns a new set with the elements that are common to both this set and the given set. この集合と与えられた集合の両方に共通である要素を持つ新しい集合を返します。

Declaration 宣言

func intersection(_ other: Self) -> Self

Parameters パラメータ

other

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

Return Value 戻り値

A new set. 新しい集合。

Discussion 解説

In the following example, the bothNeighborsAndEmployees set is made up of the elements that are in both the employees and neighbors sets. Elements that are in only one or the other are left out of the result of the intersection. 次の例において、bothNeighborsAndEmployees集合はemployeesneighbors集合の両方にある要素から作り上げられます。どちらか一方にだけある要素は、交叉の結果から除外されます。


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

Default Implementations 省略時実装

OptionSet Implementations

See Also 参照

Combining Sets 集合を結合する