AnyValidation

public protocol AnyValidation

A type-erased validation type.

This protocol uses Any instead of an associated type for the validation method paramater. It also uses a type property to store what the expected input type is.

  • The type that is expected as input for the validate method.

    If you are conforming to the higher-level Validation protocol, you should keep the default value.

    Declaration

    Swift

    static var type: Any.Type
  • Validations that should also be run on a new value, besides the main validation.

    If your type conforms to Validation, you can get valiedations that take in the correct type using safeSubvalidations.

    Declaration

    Swift

    static var subvalidations: [AnyValidation.Type]
  • Validates the value passed in. The an unexpected type is received, the ValidationError.invalidType will be thrown.

    Declaration

    Swift

    static func validate(_ value: Any)throws

    Parameters

    value

    The value to validate.

  • unsafeRun(_:type:) Extension method

    Runs the currenct validation and any subvalidations. This runs recursively until the bottom of the validation tree is found.

    Declaration

    Swift

    public static func unsafeRun(_ value: Any, type: Any.Type? = nil)throws

    Parameters

    value

    The value to validate.

    type

    The type that the valisation must support. If nil is passed in, the type is not checked and you could get a ValidationError.invalidType error.