Observe State and Send Data
-
A collector object that registers secure input fields (
VGSTextField) and submits their data/files to a VGS Vault.Summary: Provides the orchestration layer for secure data collection: field registration, state observation, JSON/body construction, vault/network submission, tokenization/alias creation and file lifecycle management.
Responsibilities:
- Registers text fields automatically when a
VGSConfigurationreferencing this collector is assigned. - Observes editing state via
observeFieldState(focused field) andobserveStates(all fields snapshot). - Submits values with
sendData/sendFile(closure, async/await, Combine variants). - Performs tokenization (
tokenizeData) and alias creation (createAliases), plus card creation via CMP (createCard). - Cleans up attached files after successful upload (
cleanFiles).
Security:
- Never logs or exposes raw sensitive values through public APIs.
- Avoid adding PII or secrets to
customHeaders&fieldNamevalues; use them strictly for routing/auth metadata. - Internal storage is transient and cleared/replaced as input changes; persistence is the caller’s responsibility (and should only store aliases).
Usage:
- Initialize with vault id & environment:
let collector = VGSCollect(id: vaultId, environment: .sandbox). - Create a
VGSConfigurationper field and assign to eachVGSTextField(registration happens automatically). - Optionally set observation closures for validation/UI updates.
- Validate all required fields (
state.isValid) before calling a submit method. - Parse response aliases/tokens; discard raw user input from UI components.
- After file submission success, call
cleanFiles().
Invariants / Preconditions:
idmust be a non-empty vault identifier.- All required fields should be valid before invoking submission APIs.
- Only one logical file should be attached when calling
sendFile. - For alias creation (
createAliases), appropriate authentication must be provided incustomHeaders. - UI access (field state collection) occurs on the main thread; ensure you invoke async calls from the main actor when updating UI.
See also:
VGSConfiguration(per-field setup)VGSCollectRequestOptions(JSON mapping policy)VGSValidationRuleSet(custom validation)
Declaration
Swift
@MainActor public class VGSCollect - Registers text fields automatically when a
-
Organization vault environment.
See moreDeclaration
Swift
public enum Environment : String -
An object that describes
See moreVGSTextFieldstate. State attributes are read-only.Declaration
Swift
@MainActor public class VGSTextFieldState -
An object that describes
See moreVGSTextFieldstate with configurationFieldType.ssn. State attributes are read-only.Declaration
Swift
@MainActor public class VGSSSNState : VGSTextFieldState -
An object that describes
See moreVGSTextFieldstate with configurationFieldType.cardNumber. State attributes are read-only.Declaration
Swift
@MainActor public class VGSCardState : VGSTextFieldState -
A custom publisher that emits
See moreStateof a givenVGSTextField.Declaration
Swift
@available(iOS 13, *) @MainActor public struct VGSTextFieldStatePublisher : @preconcurrency Publisher -
Response enum cases for SDK requests.
See moreDeclaration
Swift
@frozen public enum VGSResponse -
Tokenization response enum cases for SDK requests.
See moreDeclaration
Swift
@frozen public enum VGSTokenizationResponse : @unchecked Sendable -
Request options.
See moreDeclaration
Swift
public struct VGSCollectRequestOptions -
Key-value data type, usually used for response format.
Declaration
Swift
public typealias JsonData = [String : Any] -
HTTP request methods
See moreDeclaration
Swift
public enum VGSCollectHTTPMethod : String -
Key-value data type, used in http request headers.
Declaration
Swift
public typealias HTTPHeaders = [String : String]
View on GitHub
Observe State and Send Data Reference