NSRangeException from removeObjectsInRange: but passed range is within bounds
Asked Answered
I

1

9

I am getting the error below, which makes no sense.

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSMutableArray removeObjectsInRange:]: range {11, 15} extends beyond bounds [0 .. 15]'

What am I doing wrong here? I am within bounds of the array. Does removing the last object in the array cause issues?

Isabelleisac answered 26/3, 2012 at 20:46 Comment(0)
P
46

The second field of an NSRange is length, not endpoint. You are trying to remove fifteen objects, starting from index 11.

Instead, you want to do something along the lines of:

[myArray removeObjectsInRange:(NSRange){11, 5}];
Pasadis answered 26/3, 2012 at 20:51 Comment(5)
@Yar: It's the exact same document, you know. :)Pasadis
I know, but I can never understand when the documents are going to be the same and when iOS and Mac are going to produce different documents (which they do, sometimes, as method differ etc.). They are not in this case, but could they be different from each other?Pyrrhic
@Yar: That's true, there are weird discrepancies. There's an interesting diagram under the "Foundation classes" section here: developer.apple.com/library/mac/documentation/Cocoa/Conceptual/…Pasadis
Ironically that document doesn't change either if you alter the prefix to ios ;) Thanks, though, figure 1-7 is interesting. I thought I was missing more stuff on iOS, actually...Pyrrhic
You can also use the NSMakeRange(location, length) function to specify ranges.Lakenyalaker

© 2022 - 2024 — McMap. All rights reserved.