Latest 2.0.0
Homepage https://github.com/serjooo/SwiftyCountry
License MIT
Platforms ios 11.0
Authors

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

  • [x] 🌎 Localized name of the country
  • [x] 🗃 All locale identifiers for a country
  • [x] 💱 All currency codes and symbols for a country
  • [x] 🗣 All languages for a country
  • [x] ☎ All dial codes
  • [x] 🇱🇧 Returns the current country the user is in
  • [x] Mentions which continent it is part of
  • [x] 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.

Latest podspec

{
    "name": "SwiftyCountry",
    "version": "2.0.0",
    "summary": "An enum powered Country that swiftifies your use of Countries in your app",
    "description": "SwiftyCountry provides a convenient way to access all countries and initialize countries. It also makes it easy to checknfor a given country or countries. It is easy to switch over also, since its an enum. There is also a bonus featurenwhere you can get all countries on a given continent and check if a country is part of any given continent. It alsonmakes it easy to put the countries easily in a UIPickerView and select from it.",
    "homepage": "https://github.com/serjooo/SwiftyCountry",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Serj": "[email protected]"
    },
    "social_media_url": "https://twitter.com/SerjAgopian",
    "platforms": {
        "ios": "11.0"
    },
    "swift_version": "5.0",
    "source": {
        "git": "https://github.com/serjooo/SwiftyCountry.git",
        "tag": "2.0.0"
    },
    "source_files": [
        "SwiftyCountry",
        "SwiftyCountry/**/*.{h,m,swift}"
    ]
}

Pin It on Pinterest

Share This