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?

1 Answer 1

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}];
Sign up to request clarification or add additional context in comments.

5 Comments

@Yar: It's the exact same document, you know. :)
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?
@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/…
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...
You can also use the NSMakeRange(location, length) function to specify ranges.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.