Instance Method

subtracting(_:)

Returns a new set containing the elements of this set that do not occur in the given set.

Declaration

func subtracting(_ other: IndexSet) -> IndexSet

Parameters

other

A set of the same type as the current set.

Return Value

A new set.

Discussion

In the following example, the nonNeighbors set is made up of the elements of the employees set that are not elements of neighbors:

let employees: Set = ["Alicia", "Bethany", "Chris", "Diana", "Eric"]
let neighbors: Set = ["Bethany", "Eric", "Forlani", "Greta"]
let nonNeighbors = employees.subtract(neighbors)
print(nonNeighbors)
// Prints "["Diana", "Chris", "Alicia"]"

See Also

Removing Elements

func remove(IndexSet.Element) -> IndexSet.Element?

Remove an integer from the IndexSet.

func remove(integersIn: Range<IndexSet.Element>)

Remove a range of integers from the IndexSet.

func remove(integersIn: ClosedRange<IndexSet.Element>)

Remove a range of integers from the IndexSet.

func removeAll()

Remove all values from the IndexSet.

func subtract(IndexSet)

Removes the elements of the given set from this set.