Validator
open class Validator
Validates values against Constraints on Groups or GroupSequence with Validator.Options.
-
Initializes a new instance.
Declaration
Swift
public init() -
Validates a primitive
Encodablevalue against an array ofConstraints on a set ofGroups.Throws
AValidator.Errorif the value is not of primitive type or aConstraintViolationif the value doesn’t satisfyConstraints onGroups.Declaration
Swift
public func validate( _ value: Encodable?, against constraints: [Constraint], on groups: Set<Group> = .init() ) throwsParameters
valueA primitive
Encodablevalue to be validated.constraintsAn array of
Constraints.groupsA set of
Groups to run validations for. Defaults to an empty set. -
Validates a primitive
Encodablevalue against a variadic list ofConstraints on a set ofGroups.Throws
AValidator.Errorif the value is not of primitive type or aConstraintViolationif the value doesn’t satisfyConstraints onGroups.Declaration
Swift
public func validate( _ value: Encodable?, against constraints: Constraint..., on groups: Set<Group> = .init() ) throwsParameters
valueA primitive
Encodablevalue to be validated.constraintsA variadic list of
Constraints.groupsA set of
Groups to run validations for. Defaults to an empty set. -
Validates a primitive
Encodablevalue against an array ofConstraintTypes on a set ofGroups.Throws
AValidator.Errorif the value is not of primitive type or aConstraintViolationif the value doesn’t satisfyConstraints onGroups.Declaration
Swift
public func validate( _ value: Encodable?, against constraintTypes: [ConstraintType], on groups: Set<Group> = .init() ) throwsParameters
valueA primitive
Encodablevalue to be validated.constraintTypesAn array of
ConstraintTypes.groupsA set of
Groups to run validations for. Defaults to an empty set. -
Validates a complex
Encodablevalue against aDictionaryCollection<String, Constraint>on a set ofGroups with a list ofValidator.Options.Throws
AValidator.Errorif it can’t decode the encoded value.Declaration
Swift
public func validate( _ value: Encodable?, against constraintCollection: DictionaryCollection<String, Constraint>, on groups: Set<Group> = .init(), with options: Options = .init() ) throws -> DictionaryCollection<String, ConstraintViolation>Parameters
valueA complex
Encodablevalue to be validated.constraintCollectionA
DictionaryCollection<String, Constraint>.groupsA set of
Groups to run validations for. Defaults to an empty set.optionsA list of
Validator.Options. Defaults to an empty array.Return Value
A
DictionaryCollection<String, ConstraintViolation>. -
Validates a complex
Encodablevalue against aDictionaryCollection<String, Constraint>on aGroupSequencewith a list ofValidator.Options.Throws
AValidator.Errorif it can’t decode the encoded value.Declaration
Swift
public func validate( _ value: Encodable?, against constraintCollection: DictionaryCollection<String, Constraint>, on groupSequence: GroupSequence, with options: Options = .init() ) throws -> DictionaryCollection<String, ConstraintViolation>Parameters
valueA complex
Encodablevalue to be validated.constraintCollectionA
DictionaryCollection<String, Constraint>.groupSequenceA list of groups.
optionsA list of
Validator.Options. Defaults to an empty array.Return Value
A
DictionaryCollection<String, ConstraintViolation>. -
A common error type thrown when an invalid
See moreConstrainttype is provided to thevalidate(_:against:)method of theConstraintValidator.Declaration
Swift
public enum Error : LocalizedError
View on GitHub
Install in Dash