ElementValidation

public protocol ElementValidation: Validation where Supported: Sequence

Validates each element in a sequence using a custom validation function.

struct StringLengthArray: ElementValidation {
    typealias Supported = [String]

    static var validator: (String)throws -> Void = { str in
        guard str.count <= 1028 else { throw ValidationError(identifier: "lengthToLong", reason: "String must have length 1028 or less") }
    }
}

The validate method calls .forEach on the value passed in and passes the validator function in as the closure.

  • The function used to validate each element in the sequence.

    Declaration

    Swift

    static var validator: (Supported.Element)throws -> Void