Question

What's the best way to remove duplicate indices from an NSIndexSet? For example, say my NSIndexSet looks like this:

[ 1, 3, 3, 6, 7, 12, 12, 12 ]

I want it to look like:

[ 1, 3, 6, 7, 12 ]

What's the most efficient way to accomplish this?

Was it helpful?

Solution

NSIndexSet cannot possibly contain duplicates. What makes you think you have any?

To be more specific, the documentation states

The NSIndexSet class represents an immutable collection of unique unsigned integers, known as indexes because of the way they are used. This collection is referred to as an index set.

The key point here is the word "unique", which means it cannot contain duplicates. Attempting to add an index to an index set that's already present will result in no change.

OTHER TIPS

NSIndexSet is an immutable class. Also, from the documentation:

The NSIndexSet class represents an immutable collection of unique unsigned integers, known as indexes because of the way they are used. This collection is referred to as an index set.

Long story short, you do not have any duplicates.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top