Monday, 9 September 2013

NSRangeException while using substringWithRange:NSMakeRange

NSRangeException while using substringWithRange:NSMakeRange

I'm having an odd error I don't understand. I've looked at other
questions, and I see that NSMakeRange is anchor, distance to traverse.
This single statement causes a NSRangeException, out of bounds error
though:
if([myCompare characterAtIndex:([myCompare length]-7) == 'N'])
{
[myTemp appendString:[myCompare
substringWithRange:NSMakeRange(0,([myCompare length]-7))]];
}
In this case, I don't understand how it could EVER be out of range, since
I'm always subtracting 7 from the length of the NSString and making THAT
that range.
It might be a stupid error, but I would appreciate another set of eyes to
figure out why that is causing my NSRangeException.

No comments:

Post a Comment