CountryPicker

repository·master·Indexed 43 days ago

https://github.com/suryakantsharma/countrypicker

A Swift library for selecting countries with support for UIKit and SwiftUI. Features include search, auto-scrolling, and filtering by country name, country code, and country dial code via CountryManager.shared.

Tokens
724
Snippets
5
Records
6
Agent score
6%

What's inside CountryPicker

  1. Getting Started with UIKit and SwiftUI

    master

    Depending on your target iOS version and framework preference, refer to the following examples in the repository:

    • UIKit (Legacy/Old versions): Check the baseiOS11Example project for customization and options compatible with older UIKit implementations.
    • SwiftUI (iOS 15+): Check the baseiOS15Example project (located in CountryPickeriOS15%2B/CountryPicker13%2BExample) for using the library in SwiftUI apps with a minimum deployment target of iOS 15.
  2. Install CountryPicker via Carthage

    master
    1. Add the following line to your Cartfile:
    github "SURYAKANTSHARMA/CountryPicker"
    1. Run the update command:
    carthage update --platform iOS
    1. In Xcode, navigate to the General tab, go to Frameworks, Libraries and Embedded Content, tap the plus sign, select Add other, and locate SKCountryPicker.framework under Carthage/Build/iOS/.

    2. Add a New Run Script Phase in Build Phases with the following script:

    /usr/local/bin/carthage copy-frameworks
    1. Add the framework to Input Files: $(SRCROOT)/Carthage/Build/iOS/SKCountryPicker.framework.
  3. Configure country search filter options

    master

    The library supports filtering by countryName, countryCode, and countryDialCode. By default, it is configured to filter by countryName. You can modify the active filters using CountryManager.shared.

    // Adding filter
    CountryManager.shared.addFilter(.countryCode)
    
    // Removing filter
    CountryManager.shared.removeFilter(.countryCode)
    
    // Removing all filters
    CountryManager.shared.clearAllFilters()
  4. Retrieve country information using CountryManager

    master

    Use CountryManager.shared to look up specific country data based on different identifiers.

    // Get country based on digit code e.g: 60, +255
    CountryManager.shared.country(withDigitCode: "255")
    
    // Get country based on country name
    CountryManager.shared.country(withName: "Tanzania")
    
    // Get country based on country code e.g: MY, TZ
    CountryManager.shared.country(withCode: "MY")