Question

Say i have an NSIndexSet called aSet with numbers ranging from 26-89.

[aSet firstIndex] gives me 26

[aSet lastIndex] gives me 89

What method would give the 3rd index (29)?

Was it helpful?

Solution

I don't think NSIndexSet can be used to access like that. You'll need to iterate through it. For instance -

int indexIwantToFind = 2;
int valueAtThisIndex = [aSet firstIndex];
for(int i = 0; i < indexIwantToFind; i++){
    valueAtThisIndex = [aSet indexGreaterThanIndex:valueAtThisIndex];
}
NSLog(@"%d", valueAtThisIndex); //This will give you 39
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top