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 = ValidatorDictionary<ValidationRule>() -
Dictionary to hold fields (and accompanying errors) that were unsuccessfully validated.
Declaration
Swift
public var errors = ValidatorDictionary<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(_ field: ValidatableField, callback: (_ error:ValidationError?) -> Void)Parameters
fieldHolds 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:((_ validationRule:ValidationRule)->Void)?, error:((_ validationError:ValidationError)->Void)?)Parameters
successA closure which is called with validationRule, an object that holds validation data
errorA 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(_ field: ValidatableField, errorLabel:UILabel? = nil, rules:[Rule])Parameters
fieldfield that is to be validated.
errorLabelA UILabel that holds error label data
rulesA Rule array that holds different rules that apply to said field.
Return Value
No return value
-
This method is for removing a field validator.
Declaration
Swift
public func unregisterField(_ field:ValidatableField)Parameters
fieldfield used to locate and remove field 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:[(Validatable, ValidationError)])->Void) -> VoidParameters
callbackA closure which is called with errors, a dictionary of type Validatable:ValidationError.
Return Value
No return value.
Validator Class Reference