Validator
public class Validator
Class that makes Validator
objects. Should be added as a parameter to ViewController that will display
validation fields.
-
Dictionary to hold all fields (and accompanying rules) that will undergo validation.
Declaration
Swift
public var validations = [UITextField:ValidationRule]()
-
Dictionary to hold fields (and accompanying errors) that were unsuccessfully validated.
Declaration
Swift
public var errors = [UITextField:ValidationError]()
-
Declaration
Swift
public init(){}
Return Value
An initialized object, or nil if an object could not be created for some reason that would not result in an exception.
-
This method is used to validate a single field registered to Validator. If validation is unsuccessful, field gets added to errors dictionary.
Declaration
Swift
public func validateField(textField: UITextField, callback: (error:ValidationError?) -> Void)
Parameters
textField
Holds validator field data.
Return Value
No return value.
-
This method is used to style fields that have undergone validation checks. Success callback should be used to show common success styling and error callback should be used to show common error styling.
Declaration
Swift
public func styleTransformers(success success:((validationRule:ValidationRule)->Void)?, error:((validationError:ValidationError)->Void)?)
Parameters
success
A closure which is called with validationRule, an object that holds validation data
error
A closure which is called with validationError, an object that holds validation error data
Return Value
No return value
-
This method is used to add a field to validator.
Declaration
Swift
public func registerField(textField:UITextField, rules:[Rule])
Parameters
textField
field that is to be validated.
Rule
An array which holds different rules to validate against textField.
Return Value
No return value
-
This method is used to add a field to validator.
Declaration
Swift
public func registerField(textField:UITextField, errorLabel:UILabel, rules:[Rule])
Parameters
textfield
field that is to be validated.
errorLabel
A UILabel that holds error label data
rules
A Rule array that holds different rules that apply to said textField.
Return Value
No return value
-
This method is for removing a field validator.
Declaration
Swift
public func unregisterField(textField:UITextField)
Parameters
textField
field used to locate and remove textField from validator.
Return Value
No return value
-
This method checks to see if all fields in validator are valid.
Declaration
Swift
public func validate(delegate:ValidationDelegate)
Return Value
No return value.
-
This method validates all fields in validator and sets any errors to errors parameter of callback.
Declaration
Swift
public func validate(callback:(errors:[UITextField:ValidationError])->Void) -> Void
Parameters
callback
A closure which is called with errors, a dictionary of type UITextField:ValidationError.
Return Value
No return value.