NSIndexSet
NSIndexSet is like BitSet of Java. Mutable version is NSMutableIndexSet.
This class keeps only index(not duplicate).
Add index(NSMutableIndexSet)
NSMutableIndexSet indexes = [[NSMutableIndexSet alloc] init]; [indexes addIndex:1]; [indexes addIndex:2]; [indexes addIndex:3];
Create from index(not mutable)
NSMutableIndexSet indexes = [[NSMutableIndexSet alloc] init]; NSIndexSet* nindexes = [[NSIndexSet alloc] initWithIndexSet:indexes];
Enumeration
BlockEnumeration
[indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) { }];
Use block code. Index was kept by NSUInteger idx.
First and get next
NSUInteger idx = indexes.firstIndex;; while (idx != NSNotFound) { // idx is current index. // Next index idx = [indexes indexGreaterThanIndex:indexValue]; }