Fast enumeration on an NSIndexSet

cfischer picture cfischer · Nov 17, 2010 · Viewed 17.9k times · Source

Can you fast enumerate a NSIndexSet? if not, what's the best way to enumerate the items in the set?

Answer

Barry Wark picture Barry Wark · Nov 17, 2010

In OS X 10.6+ and iOS SDK 4.0+, you can use the -enumerateIndexesUsingBlock: message:

NSIndexSet *idxSet = ...

[idxSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
  //... do something with idx
  // *stop = YES; to stop iteration early
}];