Instance Method (Default implementation)swift 6.0.1Swift
intersection(_:)
Returns a new option set with only the elements contained in both this set and the given set.
func intersection(_ other: Self) -> Self
Parameters
- other
An option set.
Returns
A new option set with only the elements contained in both this set and other
.
This example uses the intersection(_:)
method to limit the available shipping options to what can be used with a PO Box destination.
// 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"
Implements
func intersection(Self
) -> Self Returns a new set with the elements that are common to both this set and the given set.
Other members in extension
Instance members
func symmetricDifference(Self
) -> Self Returns a new option set with the elements contained in this set or in the given set, but not in both.
func union(Self
) -> Self Returns a new option set of the elements contained in this set, in the given set, or in both.