SwiftyCountry

An enum powered Country that swiftifies your use of Countries in your app


Keywords
country, country-codes, country-names, enum, ios, macos, model, swift
License
MIT
Install
pod try SwiftyCountry

Documentation

SwiftyCountry

Build Status codecov

SwiftyCountry is an enum based model. All countries have been covered provided by Apple's Locale region codes. It provides friendly API to get: a , all locale identifiers for a country, currency code

  • 🌎 Localized name of the country
  • 🗃 All locale identifiers for a country
  • 💱 All currency codes and symbols for a country
  • 🗣 All languages for a country
  • ☎ All dial codes
  • 🇱🇧 Returns the current country the user is in
  • Mentions which continent it is part of
  • Fetch countries by continent

Installation

Cocoapods

pod 'SwiftyCountry'

Manually

Just copy the source files into your project and you're done!

Usage

Initializing

You can initialize a Country several ways:

By Country Code which is also the raw value of the enum:

let unitedStates = Country(countryCode: "us")
// The initializer doesn't care about the case of the string
let unitedStates = Country(countryCode: "uS")

By flag:

let armenia = Country("🇦🇲")

By country name; however, the drawback of using this is that it is dependent on the locale of the device:

// if locale was en_US. It is also case insensitive
let lebanon = Country(countryName: "lEbANON")

And my personal favorite is:

let germany: Country = "🇩🇪"

Since Country conforms to ExpressibleByStringLiteral this is possible. Thank you @Tawa for the contribution.

Using

Using is straightforward and eveything is documented on how it will behave

let lebanon: Country = "🇱🇧"
// Result will depend on the current locale. "Liban" if the locale was french
let countryName = lebanon.name
// Result will depend on the current locale. ٩٦١+ if the locale was arabic
let dialCode = lebanon.dialCode
// Result will be 🇱🇧
let flag = lebanon.flag

Development

Want to contribute? Great!

Best way to contribute is by submitting a pull request of a feature you think that might be useful for SwiftyCountry. We can hold a discussion in that thread of the feature.

License

MIT License

Copyright (c) 2019 Serj Agopian

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.