Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSRangeException from removeObjectsInRange: but passed range is within bounds

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?

like image 203
adrian.coroian Avatar asked Mar 26 '12 20:03

adrian.coroian


1 Answers

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}];
like image 177
jscs Avatar answered Sep 28 '22 20:09

jscs