Validator
public class Validator
Validator represents the key validator object.
-
Initializes a
Validatorobject.Declaration
Swift
public init()Return Value
An initialized object
-
Add a new basic validatable.
Declaration
Swift
public func add<V>(name: String, value: V?, rules: [ValidationRule<V>])Parameters
nameName of the validatable. Name must be unique for each cases. eg: Email
valueValue of the validatable. eg: name@domain.com
rulesArray of
ValidationRule -
Add a new custom validatable
Declaration
Swift
public func add(validatable: NamedValidatable) -
Removes a validator by its name.
Declaration
Swift
public func remove(named: String)Parameters
nameName of the validatable. It is case sensitive. eg: Email
-
Validate all validatables until error. If any error found, it will not try to validate next validatable.
Declaration
Swift
@discardableResult public func validate() throws -> BoolReturn Value
Returns
trueif valid. -
Validate all validatables until error. If any error found, it will not try to validate next validatable and return the error.
Declaration
Swift
public func errorOnValidate() -> ValidationError?Return Value
ValidationErrorif anyValidatableis invalid. -
Validate specific validatable by its name
Declaration
Swift
@discardableResult public func validate(named: String) throws -> BoolParameters
namedName of the validatable
Return Value
Returns
trueif valid. -
Validate all validatables even if any error found for one validatable.
Declaration
Swift
public func validateAll() -> [ValidationError]?Return Value
Array of
ValidationErrorif any validatable is invalid otherwise nil. -
Finds the first valid
ValidatableDeclaration
Swift
public func firstValid() -> Validatable?Return Value
Validatablethat is valid. -
Finds the first invalid
ValidatableDeclaration
Swift
public func firstInvalid() -> Validatable?Return Value
Validatablethat is invalid.
View on GitHub
Validator Class Reference