1

I have been trying to add NSRanges to an NSMutableIndexSet (for later enumeration) however I think I am misunderstanding what addIndexesinRange does. At an early point I NSMakeRange "x" number of ranges that I create from a previous NSIndexSet.

Such as:

    "NSRange: {0, 29}",
    "NSRange: {63, 96}",
    "NSRange: {132, 177}",
    "NSRange: {222, 269}",
    "NSRange: {284, 306}",
    "NSRange: {321, 330}"

And trying to add them to the new set:

NSMutableIndexSet *indexSet = [NSMutableIndexSet new];
    for (int s=0; s < array; s++) {
        NSRange ran = [[array objectAtIndex:s]rangeValue];
        [indexSet addIndexesInRange:ran];
}

Returns

[number of indexes: 617 (in 2 ranges), indexes: (0-28 63-650)]

When I want it to return the same ranges as before just inside the set, any tips?

devone
  • 293
  • 3
  • 10
  • 4
    `NSRange` is start and length, not start and end. – rmaddy Sep 09 '15 at 05:01
  • So if I got the start and end of each NSRange and used "addIndexesInRange" would that return a NSIndexSet as hoped for above is that its intended use – devone Sep 09 '15 at 05:06
  • Probably. Try it and see if it is. Define your ranges properly and it should work. – rmaddy Sep 09 '15 at 05:06
  • To be clear: the output you showed matches the input you showed. If the output isn't what you wanted, it's not because of the code you showed here, it's because of the input and whatever code created that. – Ken Thomases Sep 09 '15 at 06:53
  • Ok, yes rmaddy that worked, - "NSRange ran = [[otherSleepArray objectAtIndex:s]rangeValue]; NSUInteger b = ran.length - ran.location; [indexSet addIndexesInRange:NSMakeRange(ran.location, b)]; – devone Sep 09 '15 at 09:05

0 Answers0