cs4alhaider / CountryKit

Swift package designed to facilitate the selection and display of country information within your applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CountryKit

CountryKit is a Swift package designed to facilitate the selection and display of country information within your applications. It utilizes SwiftUI to provide a seamless and modern user interface, making it perfect for applications that require users to select their country for settings, profiles, or any other use case.

Features

  • Country Data Structure: Utilizes a struct for country information that conforms to Codable, Equatable, and Searchable protocols for efficient serialization, comparison, and searching.
  • Searchable Country List: Integrates SearchView to enable filtering countries by their name, code, or dial code, enhancing user experience by facilitating easy searches.
  • SwiftUI Country Selector: Offers a SwiftUI view component for selecting a country from a searchable list, streamlining the process of country selection in a user-friendly manner.
  • Comprehensive Country Details: Provides access to a variety of country details, including flags, local names based on the user's locale, dial codes, and unique identifiers.
  • Locale Awareness: Dynamically fetches local names of countries based on the current locale settings of the user's device.
  • Selection Persistence: Remembers the user's last country selection using UserDefaults, making for a smoother user experience.

Installation

To add CountryKit to your Xcode project using Swift Package Manager (SPM), include it as a dependency in your Package.swift file:

dependencies: [
    .package(url: "https://github.com/cs4alhaider/CountryKit.git", .upToNextMajor(from: "1.0.0"))
]

Usage

Check SearchView

A ready made example project can be fount here

Importing CountryKit

import CountryKit

Using SelectCountry View

SelectCountry { selectedCountry in
    // Handle the selected country accordingly
}

This component displays a navigable and searchable list of countries. The user's selection is returned through the provided closure.

Accessing Detailed Country Information

let selectedCountry: Country?
print(country?.flag) // Outputs the flag emoji of the selected country.

Requirements

  • iOS 17.0 or later
  • Swift 5.9 or later
  • Xcode 15.0 or later

How to Contribute

I welcome contributions of all forms. Please feel free to submit a pull request or open an issue to discuss potential changes or report bugs.

License

CountryKit is available under the MIT license. For more information, see the LICENSE file in the repository.

About

Swift package designed to facilitate the selection and display of country information within your applications

License:MIT License


Languages

Language:Swift 100.0%