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
| Property | Type | Description |
|---|---|---|
| city | String? | The city of the address. |
| country | String? | The country of the address. |
| region | String? | The region (state or province) of the address. Limited to 2 characters. |
| line1 | String? | The first line of the street address. |
| line2 | String? | The second line of the street address (optional). |
| postalCode | String? | 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
| Parameter | Type | Description |
|---|---|---|
| line1 | String? | The first line of the street address. |
| line2 | String? | The second line of the street address (if applicable). |
| city | String? | The city of the address. |
| country | String? | The country of the address. |
| region | String? | The region (state or province) of the address. Limited to 2 characters. |
| postalCode | String? | 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"