How to remove IndexSetA from IndexSetB in Swift?

199 views Asked by At

In Objective-C, the NSIndexSet can removeIndexes:(NSIndexSet *)indexSet:

[aIndexSet removeIndexes: bIndexSet];

Is there some way to do this with IndexSet in Swift like the NSIndexSet in Objective-C?

1

There are 1 answers

1
vadian On BEST ANSWER

There is a function, from the documentation

mutating func subtract(_ other: IndexSet)

Removes the elements of the given set from this set.


var aIndexSet = IndexSet(integersIn: 0..<7)
let bIndexSet = IndexSet(integersIn: 4..<12)

aIndexSet.subtract(bIndexSet)

print(aIndexSet) // 0..<3