Skip to main content
Version: Lab (preview)

Address Class

The Address structure in the Pay Theory SDK represents a physical address. It is used to store and manage address information, including street lines, city, country, region, and postal code.

Overview​

Address is a Swift structure that conforms to the Codable and Equatable protocols. It provides a standardized way to handle address information across the Pay Theory SDK.

Properties​

PropertyTypeDescription
cityString?The city of the address.
countryString?The country of the address.
regionString?The region (state or province) of the address. Limited to 2 characters.
line1String?The first line of the street address.
line2String?The second line of the street address (optional).
postalCodeString?The postal code (ZIP code) of the address.

Initializer​

public init(line1: String? = nil,
line2: String? = nil,
city: String? = nil,
country: String? = nil,
region: String? = nil,
postalCode: String? = nil)

Creates a new Address instance.

Parameters​

ParameterTypeDescription
line1String?The first line of the street address.
line2String?The second line of the street address (if applicable).
cityString?The city of the address.
countryString?The country of the address.
regionString?The region (state or province) of the address. Limited to 2 characters.
postalCodeString?The postal code (ZIP code) of the address.

Usage Example​

let address = Address(
line1: "123 Main St",
line2: "Apt 4B",
city: "Anytown",
country: "USA",
region: "CA",
postalCode: "12345"
)

// Accessing properties
print(address.city ?? "") // Outputs: Anytown
print(address.region ?? "") // Outputs: CA

// Updating properties
var mutableAddress = address
mutableAddress.postalCode = "54321"

Special Considerations​

Region Property​

The region property is constrained to a maximum of 2 characters. If a value longer than 2 characters is assigned, it will retain the previous value.

var address = Address()
address.region = "California" // This will not be set
print(address.region ?? "") // Outputs: ""

address.region = "CA" // This will be set
print(address.region ?? "") // Outputs: "CA"