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

intersection(_:)

Returns a new option set with only the elements contained in both this set and the given set. このセットと与えられたセットの両方の中に含まれる要素だけを持つ新しいオプションセットを返します。

Declaration 宣言

Parameters パラメータ

other

An option set. あるオプションセット。

Return Value 戻り値

A new option set with only the elements contained in both this set and other. この集合とotherの両方に含まれる要素のみをもつ新しいオプションセット。

Discussion 議論

This example uses the intersection(_:) method to limit the available shipping options to what can be used with a PO Box destination. この例は、intersection(_:)メソッドを使って、利用可能な出荷オプションを私書箱宛先で使われるものに制限します。


// Can only ship standard or priority to PO Boxes
let poboxShipping: ShippingOptions = [.standard, .priority]
let memberShipping: ShippingOptions =
        [.standard, .priority, .secondDay]


let availableOptions = memberShipping.intersection(poboxShipping)
print(availableOptions.contains(.priority))
// Prints "true"
print(availableOptions.contains(.secondDay))
// Prints "false"