isDisjoint(with:)
Returns a Boolean value that indicates whether the set has no members in common with the given sequence.
Declaration
func isDisjoint<S>(with other: S) -> Bool where Element == S.Element, S : SequenceParameters
- other:
A sequence of elements.
othermust be finite.
Return Value
true if the set has no elements in common with other; otherwise, false.
Discussion
In the following example, the employees set is disjoint with the elements of the visitors array because no name appears in both.
let employees: Set = ["Alicia", "Bethany", "Chris", "Diana", "Eric"]
let visitors = ["Marcia", "Nathaniel", "Olivia"]
print(employees.isDisjoint(with: visitors))
// Prints "true"