I just asked a question about how to monitor changes to a UITextField
and received this response :
- (BOOL)textField:(UITextField *)textField should
Swift Version
In Swift We need to cast textField's
text to NSString
. The following can be useful:
let newString = (textField.text! as NSString).replacingCharacters(in: range, with: string)
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString * searchStr = [textField.text stringByReplacingCharactersInRange:range withString:string];
// [textField2 setText:[textField1.text stringByReplacingCharactersInRange:range withString:string]];
NSLog(@"%@",searchStr);
return YES;
}
NSString * proposedNewString = [[textField text] stringByReplacingCharactersInRange:range withString:replacementString];