Contents

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 : Sequence

Parameters

  • other:

    A sequence of elements. other must 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"

See Also

Comparing Sets