Skip to main content
Primer Checkout iOS SDK is currently in beta (v3.0.0-beta.1). The API is subject to change before the stable release.
Represents a country in the card form’s billing address flow. PrimerCountry carries the ISO code, display name, flag emoji, and dial code, and is surfaced through PrimerCardFormState.selectedCountry once the buyer selects a country. PrimerCountry is a public struct conforming to Equatable and Identifiable, where id is the ISO code. The stable identifier makes it safe to use directly in SwiftUI List and ForEach.

Definition

@available(iOS 15.0, *)
public struct PrimerCountry: Equatable, Identifiable {
    public var id: String { code }
    public let code: String
    public let name: String
    public let flag: String?
    public let dialCode: String?

    public init(code: String, name: String, flag: String? = nil, dialCode: String? = nil)
}

Properties

PropertyTypeDescription
idStringDeterministic identifier based on country code for stable SwiftUI diffing. Equal to code.
codeStringISO 3166-1 alpha-2 country code (e.g., "US", "GB", "DE").
nameStringLocalized country name for display.
flagString?Flag emoji for the country (e.g., "🇺🇸"). nil when unavailable.
dialCodeString?International dialing code (e.g., "+1" for US). nil when unavailable.
PrimerCountry requires iOS 15.0+, matching the minimum deployment target for the Checkout Components framework.

Initializer

ParameterTypeDefaultDescription
codeStringISO 3166-1 alpha-2 country code.
nameStringLocalized country name.
flagString?nilFlag emoji for the country.
dialCodeString?nilInternational dialing code.

Reading the selected country

When billing address collection is enabled, the buyer’s chosen country is exposed on the card form state. Observe PrimerCardFormSession and read state.selectedCountry:
struct BillingCountryLabel: View {
    @ObservedObject var session: PrimerCardFormSession

    var body: some View {
        if let country = session.state.selectedCountry {
            HStack {
                Text(country.flag ?? "")
                Text(country.name)
                Text("(\(country.code))")
                    .foregroundStyle(.secondary)
            }
        } else {
            Text("Select a country")
        }
    }
}

Updating the selected country

To set the billing country programmatically, call updateCountryCode(_:) on the card form session with an ISO 3166-1 alpha-2 code. The session re-resolves state.selectedCountry into a full PrimerCountry:
session.updateCountryCode("US")
MethodDescription
updateCountryCode(_ value: String)Updates the billing country by ISO 3166-1 alpha-2 code. Updates state.selectedCountry.
Pass the same ISO code you read from country.code to round-trip a selection, for example when restoring a saved billing address.

Equatable behavior

Two PrimerCountry values are equal when all four properties (code, name, flag, dialCode) match. This makes PrimerCountry safe to compare when diffing card form state in Equatable-driven SwiftUI views.

See also

PrimerCardFormSession

Observe the card form state and update the billing country.

ValidationResult

Field-level validation results for billing address inputs.