NSRangeException from removeObjectsInRange: but passed range is within bounds

I get the error below, which does not make sense.

* Application termination due to an uncaught exception 'NSRangeException', reason: '* - [NSMutableArray removeObjectsInRange:]: range {11, 15} goes beyond [0 .. 15]'

What am I doing wrong here? I'm within the array. Does deleting the last object in the array cause problems?

+8
objective-c cocoa-touch nsmutablearray nsrange
source share
1 answer

The second NSRange field is the length, not the endpoint. You are trying to delete fifteen objects starting at index 11.

Instead, you want to do something line by line:

 [myArray removeObjectsInRange:(NSRange){11, 5}]; 
+43
source share

All Articles