iOS · macOS · watchOS · tvOS
A pure Swift library that allows you to easily convert Countries to Country Codes and Country Codes to Countries.
There is also support for other types. Currently all supported types are Countries, Alpha2Codes, Alpha3Codes and Numerics.
This project is created and maintained by Novem.
Installation
Swift Package Manager
You can use The Swift Package Manager (SPM) to install NVMRegion by adding the following description to your Package.swift
file:
import PackageDescription
let package = Package(
name: "YOUR_PROJECT_NAME",
dependencies: [
.package(url: "https://github.com/NVMNovem/NVMRegion", from: "1.0.0"),
]
)
Then run swift build
.
You can also install using SPM in your Xcode project by going to "Project->NameOfYourProject->Swift Packages" and placing "https://github.com/NVMNovem/NVMRegion" in the search field. Then select the option that is most suited for your needs.
Usage Guide
Code
To use NVMRegion, there is no initalizing required. If you want to add custom Country Aliases, you need to add the in the initalizing of your app. Example use case for a custom country name for Belgium. The example will allow the translated version "België" to be converted to a Country: "Belgium".
@main
struct MyApp: App {
init() {
NVMRegion.implementCountryAliases(["België" : .Belgium])
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
This will make it possible to create a Country() object from "België". This is not required for default country names. NVMRegion also tries to find the most fitted country for each given string.
Country("België")
This will return a valid Country() object
(
Belgium
Continent: Europe
Alpha2 Code: BE
Alpha3 Code: BEL
Numeric: N056
)