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.
- Country Data Structure: Utilizes a struct for country information that conforms to
Codable
,Equatable
, andSearchable
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.
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"))
]
A ready made example project can be fount here
import CountryKit
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.
let selectedCountry: Country?
print(country?.flag) // Outputs the flag emoji of the selected country.
- iOS 17.0 or later
- Swift 5.9 or later
- Xcode 15.0 or later
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.
CountryKit
is available under the MIT license. For more information, see the LICENSE file in the repository.