Validator

public class Validator

Validator represents the key validator object.

  • Initializes a Validator object.

    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

    name

    Name of the validatable. Name must be unique for each cases. eg: Email

    value

    Value of the validatable. eg: name@domain.com

    rules

    Array 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

    name

    Name 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.

    Throws

    Throws ValidationError if any Validatable is invalid.

    Declaration

    Swift

    @discardableResult
    public func validate() throws -> Bool

    Return Value

    Returns true if 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

    ValidationError if any Validatable is invalid.

  • Validate specific validatable by its name

    Throws

    Throws ValidationError if any Validatable is invalid.

    Declaration

    Swift

    @discardableResult
    public func validate(named: String) throws -> Bool

    Parameters

    named

    Name of the validatable

    Return Value

    Returns true if valid.

  • Validate all validatables even if any error found for one validatable.

    Declaration

    Swift

    public func validateAll() -> [ValidationError]?

    Return Value

    Array of ValidationError if any validatable is invalid otherwise nil.

  • Finds the first valid Validatable

    Declaration

    Swift

    public func firstValid() -> Validatable?

    Return Value

    Validatable that is valid.

  • Finds the first invalid Validatable

    Declaration

    Swift

    public func firstInvalid() -> Validatable?

    Return Value

    Validatable that is invalid.