> ## Documentation Index
> Fetch the complete documentation index at: https://primer.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# PrimerSelectCountryScope

> API reference for the country picker scope

`PrimerSelectCountryScope` manages the country picker UI, exposed via `PrimerCardFormScope.selectCountry`. Use it to customize the country selection experience.

## Declaration

```swift theme={"dark"}
@MainActor
public protocol PrimerSelectCountryScope
```

## Properties

| Property | Type                                    | Description                            |
| -------- | --------------------------------------- | -------------------------------------- |
| `state`  | `AsyncStream<PrimerSelectCountryState>` | Stream of country picker state changes |

### Customization

| Property      | Type                                               | Description                                                                        |
| ------------- | -------------------------------------------------- | ---------------------------------------------------------------------------------- |
| `screen`      | `((PrimerSelectCountryScope) -> AnyView)?`         | Full screen replacement                                                            |
| `searchBar`   | `((String, (String) -> Void, String) -> AnyView)?` | Custom search bar. Parameters: query, onQueryChange, placeholder                   |
| `countryItem` | `CountryItemComponent?`                            | Custom country row. Signature: `(PrimerCountry, @escaping () -> Void) -> any View` |

## Methods

| Method                                        | Description                     |
| --------------------------------------------- | ------------------------------- |
| `onCountrySelected(countryCode:countryName:)` | Select a country                |
| `cancel()`                                    | Cancel the picker               |
| `onSearch(query:)`                            | Filter countries by search text |

## Accessing the scope

The country picker scope is accessed through `PrimerCardFormScope.selectCountry`:

```swift theme={"dark"}
if let cardScope: PrimerCardFormScope = checkoutScope.getPaymentMethodScope(PrimerCardFormScope.self) {
  let countryScope = cardScope.selectCountry

  // Customize the country picker
  countryScope.countryItem = { country, onSelect in
    AnyView(
      Button(action: onSelect) {
        HStack {
          if let flag = country.flag {
            Text(flag)
          }
          Text(country.name)
          Spacer()
          Text(country.code)
            .foregroundColor(.secondary)
        }
        .padding(.vertical, 8)
      }
    )
  }
}
```

## PrimerSelectCountryState

```swift theme={"dark"}
public struct PrimerSelectCountryState: Equatable {
  var countries: [PrimerCountry]
  var filteredCountries: [PrimerCountry]
  var searchQuery: String
  var isLoading: Bool
  var selectedCountry: PrimerCountry?
}
```

| Property            | Type              | Description                     |
| ------------------- | ----------------- | ------------------------------- |
| `countries`         | `[PrimerCountry]` | All available countries         |
| `filteredCountries` | `[PrimerCountry]` | Countries matching search query |
| `searchQuery`       | `String`          | Current search text             |
| `isLoading`         | `Bool`            | Loading state                   |
| `selectedCountry`   | `PrimerCountry?`  | Currently selected country      |

## PrimerCountry

```swift theme={"dark"}
public struct PrimerCountry: Equatable {
  let code: String      // ISO 3166-1 alpha-2 (e.g., "US")
  let name: String      // Localized name
  let flag: String?     // Flag emoji
  let dialCode: String? // Dialing code
}
```

## See also

<CardGroup cols={2}>
  <Card title="PrimerCardFormScope" icon="credit-card" href="/sdk/ios-checkout/v3.0.0-beta/api-reference/primer-card-form-scope">
    Parent scope for the country picker
  </Card>
</CardGroup>
