Validator

public protocol Validator

This protocol needs to be implemented in order to add a requirement to a wrapped type. Implementers receive the wrapped type and need to determine if its values fulfill the requirements of the wrapper type. ~~~ struct NonEmptyStringValidator: Validator { static func validate(value: String) -> Bool { return !value.isEmpty } } ~~~

  • Validates if a value of the wrapped type fullfills the requirements of the wrapper type.

    Declaration

    Swift

    static func validate(_ value: WrappedType) throws -> Bool

    Parameters

    validate

    An instance of the WrappedType

    Return Value

    A Bool indicating success(true)/failure(false) of the validation