ConstraintType

public enum ConstraintType

A simplified API for the existing Constraints.

  • Creates a AndConstraint type with an array of child constraint types and a set of Groups to group by.

    Declaration

    Swift

    case and(_: [`Self`], groups: Set<Group> = .init())

    Parameters

    constraintTypes

    An array of child constraint types.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • Creates a BlankConstraint type with a custom error message and a set of Groups to group by.

    Declaration

    Swift

    case blank(_: String = BlankConstraint.message, groups: Set<Group> = .init())

    Parameters

    message

    A custom error message. Defaults to the default error message.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • Creates an BoolConstrainttype with a custom error message and a set of Groups to group by.

    Declaration

    Swift

    case bool(_: String = BoolConstraint.message, groups: Set<Group> = .init())

    Parameters

    message

    A custom error message. Defaults to the default error message.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • Creates a ChoiceConstraint type with a list of choices, a custom error message and a set of Groups to group by.

    Declaration

    Swift

    case choice(
        _ choices: [any Encodable & Equatable] = .init(),
        message: String = ChoiceConstraint.message,
        groups: Set<Group> = .init()
    )

    Parameters

    choices

    A list of choices. Defaults to an empty array.

    message

    A custom error message. Defaults to the default error message.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • Creates a DateConstrainttype with a custom DateFormatter, a custom error message and a set of Groups to group by.

    Declaration

    Swift

    case date(
        _ dateFormatter: DateFormatter = .iso8601,
        message: String = DateConstraint.message,
        groups: Set<Group> = .init()
    )

    Parameters

    dateFormatter

    A custom DateFormatter. Defaults to the “iso8601” DateFormatter.

    message

    A custom error message. Defaults to the default error message.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • Creates an EmailConstrainttype with a custom error message and a set of Groups to group by.

    Declaration

    Swift

    case email(_: String = EmailConstraint.message, groups: Set<Group> = .init())

    Parameters

    message

    A custom error message. Defaults to the default error message.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • Creates an IntegerConstrainttype with minimum/maximum values, custom minimum/maximum error messages, and a set of Groups to group by.

    Declaration

    Swift

    case integer(
        min: Int = IntegerConstraint.min,
        max: Int = IntegerConstraint.max,
        minMessage: String = IntegerConstraint.minMessage,
        maxMessage: String = IntegerConstraint.maxMessage,
        exactMessage: String = IntegerConstraint.exactMessage,
        groups: Set<Group> = .init()
    )

    Parameters

    min

    A custom minimum value. Defaults to the default minimum value.

    max

    A custom maximum value. Defaults to the default maximum value.

    minMessage

    A custom error message to show for a minimum value violation. Defaults to the default minimum value violation error message.

    maxMessage

    A custom error message to show for a maximum value violation. Defaults to the default maximum value violation error message.

    exactMessage

    A custom error message to show for an exact value violation. Defaults to the default exact value violation error message.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • Creates an IPConstrainttype with a custom error message and a set of Groups to group by.

    Declaration

    Swift

    case ip(_: String = IPConstraint.message, groups: Set<Group> = .init())

    Parameters

    message

    A custom error message. Defaults to the default error message.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • Creates a JSONConstraint type with a custom error message and a set of Groups to group by.

    Declaration

    Swift

    case json(_: String = JSONConstraint.message, groups: Set<Group> = .init())

    Parameters

    message

    A custom error message. Defaults to the default error message.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • Creates a LengthConstraint type with minimum/maximum values, custom minimum/maximum error messages, and a set of Groups to group by.

    Declaration

    Swift

    case length(
        min: UInt = LengthConstraint.min,
        max: UInt = LengthConstraint.max,
        minMessage: String = LengthConstraint.minMessage,
        maxMessage: String = LengthConstraint.maxMessage,
        exactMessage: String = LengthConstraint.exactMessage,
        groups: Set<Group> = .init()
    )

    Parameters

    min

    A custom minimum value. Defaults to the default minimum value.

    max

    A custom maximum value. Defaults to the default maximum value.

    minMessage

    A custom error message to show for a minimum value violation. Defaults to the default minimum value violation error message.

    maxMessage

    A custom error message to show for a maximum value violation. Defaults to the default maximum value violation error message.

    exactMessage

    A custom error message to show for an exact value violation. Defaults to the default exact value violation error message.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • Creates a NotBlankConstraint type with a custom error message and a set of Groups to group by.

    Declaration

    Swift

    case notBlank(_: String = NotBlankConstraint.message, groups: Set<Group> = .init())

    Parameters

    message

    A custom error message. Defaults to the default error message.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • Creates a OrConstraint type with an array of child constraint types and a set of Groups to group by.

    Declaration

    Swift

    case or(_: [`Self`], groups: Set<Group> = .init())

    Parameters

    constraintTypes

    An array of child constraint types.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • Creates a RegexConstraint type with a regular expression pattern, a custom error message and a set of Groups to group by.

    Declaration

    Swift

    case regex(
        _ pattern: String = RegexConstraint.pattern,
        message: String = RegexConstraint.message,
        groups: Set<Group> = .init()
    )

    Parameters

    pattern

    A regular expression pattern. Matches to any character(s) or an empty string by default.

    message

    A custom error message. Defaults to the default error message.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • Creates a URLConstraint type with a file URL flag, a custom error message, and a set of Groups to group by.

    Declaration

    Swift

    case url(_: String = URLConstraint.message, isFileURL: Bool = false, groups: Set<Group> = .init())

    Parameters

    message

    A custom error message. Defaults to the default error message.

    isFileURL

    Indicates whether it is a file URL or not. Defaults to false.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • Creates a UUIDConstraint type with a custom error message and a set of Groups to group by.

    Declaration

    Swift

    case uuid(_: String = UUIDConstraint.message, groups: Set<Group> = .init())

    Parameters

    message

    A custom error message. Defaults to the default error message.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • Creates a VINConstraint with a custom error message and a set of Groups to group by.

    Declaration

    Swift

    case vin(_: String = VINConstraint.message, groups: Set<Group> = .init())

    Parameters

    message

    A custom error message. Defaults to the default error message.

    groups

    A set of Groups to group by. Defaults to an empty set.

  • A matching Constraint for a ConstraintType.

    Declaration

    Swift

    public var constraint: Constraint { get }