Skip to main content

Groups (iOS SDK)

Working with multiple secure components together supports two distinct use cases:

  • Validation - checking that two or more fields hold identical values (for example, password, and confirm-password) without exposing the underlying plaintext.
  • Bulk tokenization - submitting several secure fields to Weavr in a single call and receiving one token per field.

Both use cases are covered by array and dictionary extensions on SecureTextField - secureInputsMatch and tokenise().

Migrating from UXComponentGroup

UXComponents.createGroup and the UXComponentGroup/UXComponentGroupProtocol types are deprecated in favor of these extensions, but keep working. See the v3.8.0 migration guide for a side-by-side comparison.

Validating that fields match​

secureInputsMatch returns true when all the fields in an array or dictionary contain identical values. Typical use is wiring it to your form's submit action:

@IBAction func submitTapped(_ sender: UIButton) {
if [passwordField, confirmPasswordField].secureInputsMatch {
// Inputs are identical - proceed to tokenize and submit.
} else {
showAlert(title: "Passwords don't match")
}
}

secureInputsMatch also works on a dictionary of fields:

let matches = [
"password": passwordField,
"passwordConfirm": confirmPasswordField,
].secureInputsMatch

secureInputsMatch is a local-only check - it doesn't tokenizeTokenizeReplace a card's primary account number (PAN) with a unique digital token that stands in for the real card during a transaction. When a cardholder adds a card to Apple Pay or Google Pay via push provisioning, the wallet provider stores a device-specific token rather than the underlying PAN, so the real card number isn't exposed on the device or shared with merchants. the fields or contact our backend.

Bulk tokenization​

Calling tokenise() on a dictionary of SecureTextField tokenizesTokenizeReplace a card's primary account number (PAN) with a unique digital token that stands in for the real card during a transaction. When a cardholder adds a card to Apple Pay or Google Pay via push provisioning, the wallet provider stores a device-specific token rather than the underlying PAN, so the real card number isn't exposed on the device or shared with merchants. every field in one call and returns a GroupTokenisationResult. The key you supply for each field is echoed back alongside its token:

let result = await [
"password": passwordField,
"passwordConfirm": confirmPasswordField,
].tokenise()

switch result {
case .success(let tokenisedValues, let traceability):
let passwordToken = tokenisedValues["password"]
let confirmToken = tokenisedValues["passwordConfirm"]
// Submit the tokens to your backend.
case .invalidInput(let traceability):
// A field value failed local validation before any request was sent, e.g. an
// empty field. Show an inline validation error instead of retrying.
case .serverError(let code, let message, let traceability):
// The server rejected the request. Show a generic error and let the user retry.
case .networkFailure(let cause, let traceability):
// The device couldn't reach the server. Retry once connectivity is restored.
case .failure(let cause, let traceability):
// An unexpected error occurred. Retry, and share `traceability` with our
// support team if it keeps happening.
}

tokenise() is also available directly on a single SecureTextField, returning a TokenisationResult:

let result = await passwordField.tokenise()

switch result {
case .success(let token, let traceability):
// Submit the token to your backend.
case .invalidInput(let traceability):
// The field value failed local validation before any request was sent, e.g. an
// empty field. Show an inline validation error instead of retrying.
case .serverError(let code, let message, let traceability):
// The server rejected the request. Show a generic error and let the user retry.
case .networkFailure(let cause, let traceability):
// The device couldn't reach the server. Retry once connectivity is restored.
case .failure(let cause, let traceability):
// An unexpected error occurred. Retry, and share `traceability` with our
// support team if it keeps happening.
}