My class is registered as the text field delegate, and part of its function includes implementing textField:shouldChangeCharactersInRange:replacementString like this:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
self.stateHolder.fieldValue = [self.stateHolder.fieldValue stringByReplacingCharactersInRange:range withString:string];
return YES;
}
I started noticing a crash when entering diacritics from the hardware keyboard into an empty text field. Here's the error I'm seeing:
Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFString replaceCharactersInRange:withString:]: Range or index out of bounds'
It appears that when entering the diacritic from a hardware keyboard, the range that is associated with entering it is "location=1, length=0". This is what's causing an index out of bounds exception when trying to save it in the string. Does anyone know of a way around this crash?