I can't seem to find a suitable example of how to use "indexPassingTest" with an NSIndexSet. I am trying to compare to NSIndexSets, in order to find the difference. I was hoping to use the following code:
NSIndexSet *selectionIndexesNew = [change objectForKey:@"new"];
NSIndexSet *selectionIndexesOld = [change objectForKey:@"old"];
NSUInteger newSelection = 0;
newSelection = [selectionIndexesNew indexPassingTest:^BOOL(NSUInteger idx, BOOL *stop) {
*stop = NO;
if ([selectionIndexesOld containsIndex:idx] == NO) {
*stop = YES;
}
return idx;
}];
This doesn't seem to iterate through my NSIndexSet at all. The first value from selectionIndexesNew is used, but subsequent values are ignored. My understanding of this method is that all Index values are iterated. Or am I wrong on this?
Ok, figured it out, right after posting this.. You have to return
NOif your idx doesn't match. PassingYESif the index matches.Here is code that seems to work. (This has not been extensively tested..)