ConstraintSet
public struct ConstraintSet<T>
A generic collection of Constraints
on which an input can be validated on.
-
Returns the number of constraints in collection
Declaration
Swift
public var count: Int { get }
-
Create a new
ConstraintSet
instanceDeclaration
Swift
public init()
-
Create a new
ConstraintSet
instance populated with a predefined list ofConstraints
Declaration
Swift
public init<C>(constraints: [C]) where T == C.InputType, C : Constraint
Parameters
constraints
[Constraint]
-
Create a new
ConstraintSet
instance populated with a unsized list ofConstraints
Declaration
Swift
public init<C>(constraints: C...) where T == C.InputType, C : Constraint
Parameters
constraints
[Constraint]
-
Adds a
Constraint
to the generic collection of constraints.Declaration
Swift
mutating func add<C>(constraint: C) where T == C.InputType, C : Constraint
Parameters
constraint
-
Evaluates the input on all
Constraints
until the first fails.Declaration
Swift
func evaluateAny(input: T) -> ValidationResult
Parameters
input
The input to be validated.
Return Value
.success
if the input is valid,.failure
containing theError
registered with the failingConstraint
otherwise. -
Evaluates the input on all `Constraints in the collection.
Declaration
Swift
func evaluateAll(input: T) -> ValidationResult
Parameters
input
The input to be validated.
Return Value
An array of
Result
elements, indicating the evaluation result of eachConstraint
in collection.
-
Builds a
PredicateConstraint
instance and adds it to the generic collection of constraints.Declaration
Swift
public mutating func add<P>(predicate: P, error: Error) where T == P.InputType, P : Predicate
Parameters
predicate
A
Predicate
to describes the evaluation rule.message
An
Error
that describes why the evaluation has failed.