Reputation: 5130
In my app I want to validate user inputs
in the fields. For Example
If textfields is empty. Or email is in correct format
I don't want to add validation logic in ViewController, Neither I want to pass UIView to a Validator Class
I have multiple screens like this.
Any suggestion for best ways validating Screens.
Upvotes: 0
Views: 1924
Reputation: 10959
what you can do is create category
class of UIView
and write instance method like
Validation+UIView
+(BOOL)isEmpty:(NSString *)string{
// snippet to check empty validation and return value.
}
+(BOOL)emailValidation:(NSString *)string{
// snippet to check email validation and return value.
}
Now use this instance method on your view.
if(![yourview isEmpty]){
// all good ...
}
Upvotes: 2
Reputation: 9346
If you are targeting it for multiple scenes then it is good to have a validator class for all your UITextFields
. I have written a UITextField validator class which is very simple to use. You can modify it as you want. Take a look. Best luck
Upvotes: 1