Validator

public final class Validator

A default Validator class to validate a value with multiple types of Constraints.

  • Initializes a new instance.

    Declaration

    Swift

    public init()
  • Validates a value against an array of Constraints.

    Throws

    An error type of ConstraintViolation.

    Declaration

    Swift

    public func validate(_ value: String, against constraints: [Constraint], on groups: Set<Group> = .init()) throws

    Parameters

    value

    A value to be validated.

    constraints

    An array of Constraints.

    groups

    Validation groups to run validation on. Defaults to an empty array.

  • Validates a value against a variadic list of Constraints.

    Throws

    An error type of ConstraintViolation.

    Declaration

    Swift

    public func validate(
        _ value: String,
        against constraints: Constraint...,
        on groups: Set<Group> = .init()
    ) throws

    Parameters

    value

    A value to be validated.

    constraints

    A variadic list of Constraints.

    groups

    Validation groups to run validation on. Defaults to an empty array.

  • Validates a value against an array of ConstraintTypes.

    Throws

    An error type of ConstraintViolation.

    Declaration

    Swift

    public func validate(
        _ value: String,
        against constraintTypes: [ConstraintType],
        on groups: Set<Group> = .init()
    ) throws

    Parameters

    value

    A value to be validated.

    constraintTypes

    An array of ConstraintTypes.

    groups

    Validation groups to run validation on. Defaults to an empty array.

  • A common error type to throw when an invalid Constraint is provided to a ConstraintValidator.

    See more

    Declaration

    Swift

    public enum Error : LocalizedError