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

intersection(_:)

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

Declaration 宣言

func intersection(_ other: Set<Element>) -> Set<Element>

Parameters パラメータ

other

Another 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"]"

Relationships 関係

From Protocol 由来プロトコル

See Also 参照

Combining Sets 集合を結合する