GenericTextFormatter
open class GenericTextFormatter : FormattedStringEditing
A GenericTextFormatter implementation to format custom patterns.
This formatter accepts different character types based on pattern markers. Each marker defines what type of character is allowed at that position. Unmatched characters will be ignored during input.
The pattern markers are: A: Requires a letter (a-z, A-Z) N: Requires a number (0-9) X: Accepts either a letter or number S: Requires a special character *: Accepts any character YY/YYYY: Represents 2 or 4 digit year MM: Represents 2 digit month DD: Represents 2 digit day Use back space to specify a location for the special characters
-
Format validation error types
See moreDeclaration
Swift
public enum FormatError : Int -
Each character in the format string is either:
- A pattern marker (A, N, X, S, *, YY, YYYY, MM, DD)
- A literal character (displayed as-is)
- An escaped special character (prefixed with )
For example: If the format string is AA NNN NNNS X YYYY/MM/DD \A* and user input “CA234567!U20250605” then it will display “CA 234 567! U 2025/06/05 A*”
Declaration
Swift
public var format: String { get set } -
Minimum allowed year value (default: 1900)
Declaration
Swift
public var yearMinium: Int -
Maximum allowed year value (default: 2099)
Declaration
Swift
public var yearMaximum: Int -
Format validation error state
Declaration
Swift
public var formatError: FormatError -
Whether to enable strict date format validation (default: false)
Note
When enabled, invalid date formats will trigger fatalErrorDeclaration
Swift
public var isDateFormatValidationStrict: Bool -
Flag indicating whether the content has been formatted in SwiftUI’s TextField
Declaration
Swift
public var formatted: Bool -
The constructor.
Declaration
Swift
public init()