I have so many UITextField in my App.
I don't want to allow user to enter special characters those textfields.
I know, I can use shouldChangeCharactersInRange delegate method of UITextFiled and validate it, But this approach is feasible for 5-8 UITextFiled not for 15-20.
I want to validate those(15-20) UITextFileds using RuntimeAttributes and UICategory as below links:-
http://spin.atomicobject.com/2014/05/30/xcode-runtime-attributes/
I tried and create UICategory of UITextFiled as below:-
UITextField+RunTimeExtension.h
@interface UITextField (RunTimeExtension)
@property(nonatomic,assign) BOOL *isAllowedSpecialCharacters;
@end
UITextField+RunTimeExtension.m
-(void)setIsAllowedSpecialCharacters:(BOOL *)isAllowedSpecialCharacters{
-(BOOL)isIsAllowedSpecialCharacters{
if(self.isAllowedSpecialCharacters){
NSCharacterSet *characterSet = [[NSCharacterSet alphanumericCharacterSet] invertedSet];
NSString *filtered = [[self.text componentsSeparatedByCharactersInSet:characterSet] componentsJoinedByString:@""];
return [self.text isEqualToString:filtered] || [self.text isEqualToString:@" "];
}else{
return NO;
}
}
and add this attribute in RuntimeAttribute as below image:
But didn't work, if this property is checked or not.