ConditionedAsyncConstraint

public class ConditionedAsyncConstraint<T> : AsyncConstraint

A structrure that links an AsyncPredicate to an Error that describes why the predicate evaluation has failed.

  • Declaration

    Swift

    public typealias InputType = T
  • Create a new ConditionedAsyncConstraint instance

    Declaration

    Swift

    public init<P>(predicate: P, error: Error) where T == P.InputType, P : AsyncPredicate

    Parameters

    predicate

    An AsyncPredicate to describes the evaluation rule.

    error

    An Error that describes why the evaluation has failed.

  • Create a new ConditionedAsyncConstraint instance

    Declaration

    Swift

    public init<P: AsyncPredicate>(predicate: P, error: @escaping (InputType) -> Error) where P.InputType == InputType

    Parameters

    predicate

    An AsyncPredicate to describes the evaluation rule.

    error

    An generic closure that dynamically builds an Error to describe why the evaluation has failed.

  • Add a condition AsyncConstraint.

    Declaration

    Swift

    public func add<C>(condition: C) where T == C.InputType, C : AsyncConstraint

    Parameters

    constraint
  • Asynchronous evaluates the input on the Predicate.

    Declaration

    Swift

    public func evaluate(with input: InputType, queue: DispatchQueue, completionHandler: @escaping (_ result: ValidationResult) -> Void)

    Parameters

    input

    The input to be validated.

    queue

    The queue on which the completion handler is executed.

    completionHandler

    The completion handler to call when the evaluation is complete. It takes a Bool parameter:

    result

    .success if the input is valid, .failure containing the Summary of the failing Constraints otherwise.