The CountryCodesSwift
library is a Swift package designed for managing and working with country codes and phone number dial codes efficiently. With this library, you can:
- Recognize the countries associated with phone number dial codes.
- Group country codes by their respective dial codes for easy access.
You can seamlessly integrate the CountryCodesSwift
library into your Swift projects using Swift Package Manager (SPM).
- In Xcode, navigate to "File" -> "Swift Packages" -> "Add Package Dependency..."
- Enter the repository URL:
https://github.com/Samback/CountryCodesSwift.git
. - Select the library and add it to your project's target.
The CountryCodesSwift
struct simplifies the loading and management of country codes:
let countryCodesInstance = CountryCodesSwift()
The library will automatically attempt to load the country codes from a JSON file. If an error occurs during loading, it will handle it gracefully.
You can easily determine the countries associated with phone number dial codes using the recognizeCountries(with:)
method:
let phoneNumber = "+134645756"
let recognizedCountries = countryCodesInstance.recognizeCountries(with: phoneNumber)
The library provides a countryCodesByDialCode
property, allowing you to access country codes grouped by their respective dial codes:
let countryCodesByDialCode = countryCodesInstance.countryCodesByDialCode
The library includes example tests that demonstrate its functionality. You can refer to these tests in the test target of your project for further guidance on usage.
func testCheckUSACountryCodeAndCanada() {
// Test recognizing USA and Canada from a phone number
}
func testCheckUkraine() {
// Test recognizing Ukraine from a phone number
}
func testChekUnitedKingdomAndIslands() {
// Test recognizing the United Kingdom and Islands from a phone number
}
Contributions to the CountryCodesSwift
library are welcomed! If you have bug fixes, improvements, or new features to suggest, please open an issue or submit a pull request.
This library is available under the MIT License. Feel free to use it in your projects, and contributions are highly appreciated.
Thank you for choosing the CountryCodesSwift
library! If you encounter any issues or have questions, please don't hesitate to reach out for assistance.