UI Elements
-
A secure input view that masks, formats, and validates sensitive user data before submission via
VGSCollect.Summary: Acts as the primary UI component for secure data entry (card number, CVC, expiration date, SSN, generic text, etc.). Provides formatting masks, validation rule application, secure raw storage abstraction, and integration hooks for tokenization.
Responsibilities:
- Applies format pattern & divider to user keystrokes (dynamic for certain types like card number).
- Exposes state snapshots (
state) throughVGSCollectobservation closures for validation & UI feedback. - Holds reference to
VGSConfigurationthat defines semantic role, validation rules, input formatting and tokenization parameters.
Formatting & Masking:
formatPattern(from configuration or dynamic adjustment) determines visible grouping (# placeholders).dividerinserted between pattern groups (e.g./for dates,-for SSN).- Card number and CVC patterns update automatically based on detected brand when using associated field types.
Validation:
- Default validation rules determined by
FieldType; can be overridden viaconfiguration.validationRules. - Validation runs on each editing change and contributes to field & form state.
Usage:
let cardField = VGSCardTextField() // or VGSTextField() let cfg = VGSConfiguration(collector: collector, fieldName: "card_number") cfg.type = .cardNumber cfg.isRequiredValidOnly = true cardField.configuration = cfg // registers with collector // Observe validity via collector.observeFieldState or cardField.state (if public)Security:
- Never read or log internal
textFieldcontents directly; rely on state metadata (last4,isValid). - Do not persist raw user-entered values (store only aliases returned from backend responses).
- Avoid copying sensitive field values into analytics, crash logs, or third-party SDKs.
Performance:
- Avoid repeatedly reassigning configuration after user input begins.
Accessibility:
- Customize accessibility label/hint via provided properties; keep hints free of sensitive content.
- Ensure sufficient contrast and dynamic type scaling if
adjustsFontForContentSizeCategoryis enabled.
Invariants / Preconditions:
- A non-nil
configurationis required before using the field for secure submission. - Do not mutate
configurationwhile field is first responder to avoid inconsistent formatting.
See also:
VGSConfigurationfor defining semantic meaning & validation.VGSCollectfor submission & state observation.
Declaration
Swift
@MainActor public class VGSTextField : UIViewextension VGSTextField: UITextFieldDelegateextension VGSTextField: @preconcurrency MaskedTextFieldDelegate -
An object that displays an editable text area. Can be use instead of a
VGSTextFieldwhen need to detect and show credit card brand images.Overview:
VGSCardTextFieldextendsVGSTextFieldto provide real-time card brand detection (Visa, Mastercard, etc.) and an optional brand icon. It dynamically:- Detects card brand as the user types.
- Updates spacing/formatting pattern automatically.
- Propagates brand-specific CVC length & formatting to attached
VGSCVCTextField.
Usage:
- Create instance and assign a
VGSConfigurationwhosetypeis.cardNumber(or specialized tokenization configuration). - Optionally customize icon presentation via
cardIconLocation,cardIconSize, or supply a closure incardsIconSourcefor custom imagery. - Observe field state (
statecast toVGSCardState) to accessbin,last4, andcardBrandafter valid input.
Accessibility:
- Keep
cardIconViewIsAccessibilityElement = truefor voiceover users; setcardIconAccessibilityHintto a localized brand description. - Avoid adding sensitive PAN information to accessibility hints.
Performance: Brand detection runs on each input change.
Security:
- No raw PAN characters are logged or exposed via public API.
Declaration
Swift
@MainActor public final class VGSCardTextField : VGSTextField -
An object that displays an editable text area. Can be use instead of a
VGSTextFieldwhen need to show picker view with Card Number Expiration Month and Year.Overview:
VGSExpDateTextFieldpresents a month/year picker or keyboard for collecting card expiration date securely. It auto-validates against current month to prevent past dates and adapts its formatting based on configuration.Features:
- Month & year picker with customizable label formats (
MonthFormat,YearFormat). - Prevents selection of expired month (auto-corrects if user navigates to past entry in current year).
- Supports keyboard input fallback when configuration sets
inputSource = .keyboard. - Integrates with
VGSExpDateConfigurationfor formatting & serialization, including tokenization scenarios.
Usage:
- Create text field and assign a
VGSExpDateConfiguration(or tokenization configuration) toconfigurationbefore editing begins. - Optionally set
monthPickerFormat/yearPickerFormatfor UI preferences. - Read
statefor validation errors; submit throughVGSCollect.
Accessibility:
- Picker components inherit system traits; provide a meaningful placeholder so VoiceOver announces context.
- Avoid exposing actual card number or other PII in any associated labels.
Performance:
- Data source arrays are lightweight; picker updates only on relevant component changes.
Declaration
Swift
@MainActor public final class VGSExpDateTextField : VGSTextFieldextension VGSExpDateTextField: UIPickerViewDelegate, UIPickerViewDataSource - Month & year picker with customizable label formats (
-
An object that displays an editable text area. Can be use instead of a
See moreVGSTextFieldwhen need to show picker view with a Date. It support to define a range of valid dates to select from.Declaration
Swift
@MainActor public final class VGSDateTextField : VGSTextFieldextension VGSDateTextField: UIPickerViewDelegate, UIPickerViewDataSource -
An object that displays an editable text area. Can be use instead of a
VGSTextFieldwhen need to show CVC/CVV images for credit card brands.Overview:
VGSCVCTextFieldaugmentsVGSTextFieldby rendering a brand-specific CVC/CVV helper icon whose size and position you can customize. When paired with aVGSCardTextField, the icon and validation rules adapt to the detected brand (e.g. 3 vs 4 digit CVC length).Usage:
- Assign a
VGSConfigurationwithtype = .cvc(or tokenization config) before user input. - Optionally adjust
cvcIconLocation,cvcIconSize, or supply a custom image provider viacvcIconSource. - Keep accessibility hints descriptive but free of sensitive details.
Accessibility:
cvcIconViewIsAccessibilityElementcontrols VoiceOver exposure.- Use
cvcIconAccessibilityHintfor localized explanation: e.g. “CVC help icon”.
Security:
- Avoid logging or embedding confidential data inside accessibility strings.
Declaration
Swift
@MainActor public final class VGSCVCTextField : VGSTextField - Assign a
-
Delegates produced by
See moreVGSTextFieldinstance.Declaration
Swift
@objc @MainActor public protocol VGSTextFieldDelegate -
A configuration object that defines semantic meaning, formatting and validation rules for an attached
VGSTextField.Summary: Configure how a secure text field should behave (data type, keyboard, formatting, validation, and submission key) when collecting sensitive data for VGS vault submission.
Responsibilities:
- Declares the vault JSON key (
fieldName) used during submission. - Specifies field semantic
type(e.g. card number, CVC) that drives built–in formatting & validation defaults. - Holds optional custom validation rules and formatting pattern overrides.
- Provides UI hints (keyboard type, return key, content type, appearance) without directly altering UI until bound.
Security:
fieldNameis a logical alias only; never place raw secrets or PII in the name itself.- Formatting (masking/spacing) is purely cosmetic and does NOT sanitize or truncate the raw secure value transmitted to the vault.
Usage:
- Instantiate with a
VGSCollectinstance and uniquefieldName. - Adjust optional properties (e.g.
isRequired,validationRules,formatPattern). - Assign the configuration to a
VGSTextFieldbefore user input begins.
Invariants / Preconditions:
fieldNameshould be non-empty and unique per collector to avoid ambiguous payload keys. (Not currently enforced at runtime.)- Changing properties after the field has begun editing may not retroactively re-validate already entered content.
Declaration
Swift
public class VGSConfiguration : VGSTextFieldConfigurationProtocol - Declares the vault JSON key (
-
A class responsible for configuration
See moreVGSTextFieldwithfieldType = .expDate. ExtendsVGSConfigurationclass.Declaration
Swift
@MainActor public final class VGSExpDateConfiguration : VGSConfiguration, VGSExpDateConfigurationProtocol, VGSFormatSerializableProtocol -
Class responsible for configuration
See moreVGSDateTextFieldorVGSTextFieldwithfieldType = .date. ExtendsVGSConfigurationDeclaration
Swift
@MainActor public final class VGSDateConfiguration : VGSConfiguration, VGSDateConfigurationProtocol, VGSFormatSerializableProtocol -
VGSCardHolderNameTokenizationConfiguration- textfield configuration for textfield with type.cardHolderName, required for work with tokenization api.Usage:
- Initialize with your
VGSCollectinstance and afieldName(JSON key for outbound payload). - Assign to a
VGSTextFieldbefore user begins editing. - Call
tokenizeData(routeId:)orcreateAliases(routeId:)on the collector; the response JSON will include generated alias(es).
Notes:
- Customize
tokenizationParameters.formatif you need different alias semantics. - Never include real PII inside
fieldName; it is only a logical key.
Declaration
Swift
@MainActor public class VGSCardHolderNameTokenizationConfiguration : VGSConfiguration, VGSTextFieldTokenizationConfigurationProtocol - Initialize with your
-
VGSCardNumberTokenizationConfiguration- configuration for a text field collecting card numbers (.cardNumber). Required for tokenization API usage.Summary: Specialized configuration enabling PAN tokenization while retaining dynamic brand-driven formatting and validation inherited from
VGSConfiguration.Behavior:
- Forces
typeto.cardNumber. - Supplies
tokenizationParametersconsumed by tokenization / alias APIs.
Usage:
let cardCfg = VGSCardNumberTokenizationConfiguration(collector: collector, fieldName: "card_number") cardCfg.tokenizationParameters.format = VGSVaultAliasFormat.FPE_SIX_T_FOUR.rawValue cardField.configuration = cardCfg // Later submit collector.createAliases { response in /* handle */ }Customization Notes:
- Override
tokenizationParameters.formatbefore attaching to the field to avoid mid-edit alias policy changes. - For fully opaque tokens choose
VGSVaultAliasFormat.UUID.rawValue. - Validation rules can be replaced with a custom
VGSValidationRuleSetif business logic restricts brands or lengths.
Security:
- Never log raw PAN; rely on card state (
last4, brand) for limited display needs.
Declaration
Swift
@MainActor public class VGSCardNumberTokenizationConfiguration : VGSConfiguration, VGSTextFieldTokenizationConfigurationProtocol - Forces
-
VGSCVCTokenizationConfiguration- textfield configuration for textfield with type.cvc, required for work with tokenization api.Summary: Specialized configuration subclass for CVC fields enabling tokenization when submitting via Vault API methods (e.g.
tokenizeData,createAliases).Behavior:
- Forces
typeto.cvc(override ignores external setter attempts). - Supplies
tokenizationParametersused to build tokenization request body. - Inherits formatting & validation from
VGSConfiguration; defaults still apply unless overridden.
Usage:
let cvcCfg = VGSCVCTokenizationConfiguration(collector: collector, fieldName: "card_cvc") // Optional: adjust alias format cvcCfg.tokenizationParameters.format = VGSVaultAliasFormat.FPE_SIX_T_FOUR.rawValue cvcField.configuration = cvcCfgCustomization Notes:
- Modify
tokenizationParameters.formatbefore assigning configuration to the field. - Validation rules can still be overridden via
validationRulesif needed. - Storage should remain volatile for CVC (do not switch to persistent unless explicit compliance requirements dictate).
Security:
- Tokenization reduces exposure of raw CVC; never log raw input even with tokenization enabled.
Declaration
Swift
@MainActor public class VGSCVCTokenizationConfiguration : VGSConfiguration, VGSTextFieldTokenizationConfigurationProtocol - Forces
-
VGSDateTokenizationConfiguration- configuration object for a date field tokenization.Summary: Specialized configuration for
.datefields enabling Vault tokenization, optional date-picker input, and optional format serialization before submission.Behavior:
- Forces
typeto.date. - Provides
tokenizationParametersconsumed by tokenization/alias APIs. - Supports optional date picker via
inputSource = .datePickerand year range customization (datePickerStartDate/datePickerEndDate). - Allows input/output date format conversion & serialization through
serializerscollection.
Usage:
let dateCfg = VGSDateTokenizationConfiguration(collector: collector, fieldName: "event_date") dateCfg.inputSource = .datePicker dateCfg.inputDateFormat = .mmddyyyy dateCfg.outputDateFormat = .yyyymmdd dateCfg.tokenizationParameters.format = VGSVaultAliasFormat.UUID.rawValue dateField.configuration = dateCfgCustomization Notes:
- Set format conversion properties before assigning configuration to the field.
- Provide serializers when you need extra structured output (e.g. separate year/month fields) prior to tokenization.
- Adjust start/end picker dates via initializer optional parameters.
Security:
- Tokenization replaces raw date with an alias; never log raw date content if considered sensitive (e.g. birth dates).
- Do not persist raw input.
Declaration
Swift
@MainActor public final class VGSDateTokenizationConfiguration : VGSConfiguration, VGSDateConfigurationProtocol, @preconcurrency VGSTextFieldTokenizationConfigurationProtocol, VGSFormatSerializableProtocolextension VGSDateTokenizationConfiguration: @preconcurrency VGSTextFormatConvertable - Forces
-
VGSExpDateTokenizationConfiguration- textfield configuration for textfield with type.expDate, required for work with tokenization api. Assign toVGSExpDateTextField(or genericVGSTextField) before user input to enable expiration date tokenization.Summary: Specialized configuration enabling tokenization, optional date picker input source, and raw-to-formatted expiration date conversion (short/long year) prior to submission.
Behavior:
- Forces
typeto.expDate. - Provides
tokenizationParametersconsumed by tokenization / alias APIs. - Supports picker-based entry via
inputSource = .datePickerand format conversion usinginputDateFormat/outputDateFormat. - Allows serialization into structured components through
serializersbefore alias creation.
Usage:
let expCfg = VGSExpDateTokenizationConfiguration(collector: collector, fieldName: "card_exp") expCfg.inputSource = .datePicker expCfg.inputDateFormat = .shortYear expCfg.outputDateFormat = .longYear expCfg.tokenizationParameters.format = VGSVaultAliasFormat.UUID.rawValue expCfg.serializers = [ExpDateFormatSerializer.month("exp_month"), ExpDateFormatSerializer.year("exp_year")] // example serializers expField.configuration = expCfgCustomization Notes:
- Set format conversion & serializers before assigning configuration to field for consistent initial UI.
- Use serializers only when you need extra separated alias fields (month/year) beyond the single expiration alias.
- Validation rules can be overridden with a custom
VGSValidationRuleSetif business constraints differ (e.g. extended future range).
Security:
- Treat expiration dates as sensitive.
Declaration
Swift
@MainActor public final class VGSExpDateTokenizationConfiguration : VGSConfiguration, VGSExpDateConfigurationProtocol, @preconcurrency VGSTextFieldTokenizationConfigurationProtocol, VGSFormatSerializableProtocolextension VGSExpDateTokenizationConfiguration: @preconcurrency VGSTextFormatConvertable - Forces
-
VGSSSNTokenizationConfiguration- textfield configuration for textfield with type.ssn, required for work with tokenization api.Summary: Specialized configuration enabling tokenization for SSN fields, ensuring alias creation while preserving standard SSN input formatting and validation.
Behavior:
- Forces
typeto.ssnregardless of external attempts to modify. - Supplies
tokenizationParametersconsumed by tokenization / alias APIs. - Inherits base formatting & validation from
VGSConfiguration; you may overridevalidationRulesfor custom compliance constraints.
Usage:
let ssnCfg = VGSSSNTokenizationConfiguration(collector: collector, fieldName: "user_ssn") ssnCfg.tokenizationParameters.format = VGSVaultAliasFormat.UUID.rawValue ssnField.configuration = ssnCfgCustomization Notes:
- Adjust alias format prior to assigning configuration to avoid mid-edit format shifts.
- Do not relax SSN regex to avoid collecting malformed identifiers.
Security:
- Treat SSN as highly sensitive.
Declaration
Swift
@MainActor public class VGSSSNTokenizationConfiguration : VGSConfiguration, VGSTextFieldTokenizationConfigurationProtocol - Forces
-
VGSTokenizationConfiguration- textfield configuration for a text field with any supportedFieldType, enabling tokenization when no specialized configuration exists.Summary: Generic catch-all tokenization configuration. Use for field types like
.cardHolderName,.none, or custom data keys where dedicated tokenization subclasses are not provided.Behavior:
- Inherits all formatting, validation, and requirement handling from
VGSConfiguration. - Adds
tokenizationParametersconsumed by Vault tokenization / alias creation APIs (tokenizeData,createAliases).
Usage:
let nameCfg = VGSTokenizationConfiguration(collector: collector, fieldName: "card_holder") nameCfg.type = .cardHolderName nameCfg.tokenizationParameters.format = VGSVaultAliasFormat.UUID.rawValue nameField.configuration = nameCfg // Later: collector.createAliases { response in /* handle alias mapping */ }Customization Notes:
- Set
typeand anyvalidationRulesbefore tokenization to ensure correct evaluation. - For highly sensitive transient values consider switching
storageto.VOLATILE(alias may not be reusable long-term). - Use a deterministic alias format only if your backend requires stable pattern characteristics.
Security:
- Never log raw input pre-tokenization.
Declaration
Swift
@MainActor public class VGSTokenizationConfiguration : VGSConfiguration, VGSTextFieldTokenizationConfigurationProtocol - Inherits all formatting, validation, and requirement handling from
-
Define the methods and properties the date configuration must have
See moreDeclaration
Swift
@MainActor public protocol VGSDateConfigurationProtocol -
Attributes required to configure date format and input source for field with type
See more.expDate.Declaration
Swift
@MainActor public protocol VGSExpDateConfigurationProtocol -
Type of
See moreVGSTextFieldconfiguration.Declaration
Swift
public enum FieldType : Int, CaseIterable -
Format used to validate a VGS date text input
See moreDeclaration
Swift
@MainActor public enum VGSDateFormat : InputConvertableFormat, OutputConvertableFormat, Sendable -
See moreStructthat represents a date includingyear,monthandday. It doesn’t includehours,minutesorseconds.Declaration
Swift
public struct VGSDateextension VGSDate: Comparable -
Type of
See moreVGSTextFieldinput source.Declaration
Swift
public enum VGSTextFieldInputSource
View on GitHub
UI Elements Reference