i begin with reactiveCocoa and i have some trouble with UITextfield. i try to do a basic check on a textField to display only 4 digit.
i try to follow this exemple: http://nshipster.com/reactivecocoa/ but in here, shouldChangeCharactersInRange is always true so the textfield is always updated.
i tried 2 solution :
[RACSignal combineLatest:@[self.pinDigitField.rac_textSignal] reduce:^(NSString *pinDigit) { NSCharacterSet *numbersOnly =[NSCharacterSet characterSetWithCharactersInString:@"0123456789"]; NSCharacterSet *characterSetFromTextField = [NSCharacterSet characterSetWithCharactersInString:pinDigit]; return @([numbersOnly isSupersetOfSet:characterSetFromTextField] && text.length < 5); }];
and this one
[[self.pinDigitField.rac_textSignal filter:^BOOL(id value) { NSString *text = value; NSCharacterSet *numbersOnly = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"]; NSCharacterSet *characterSetFromTextField = [NSCharacterSet characterSetWithCharactersInString:text]; BOOL stringIsValid = [numbersOnly isSupersetOfSet:characterSetFromTextField] && text.length < 5 ;return stringIsValid; }]subscribeNext:^(id x) { NSLog(@"valid"); }];
in both case i can't simply not write the new caracter in the UITextfield.
does anybody have an idea?