Skip to content

Instantly share code, notes, and snippets.

@munirwanis
Last active December 8, 2017 00:52
Show Gist options
  • Save munirwanis/358532b5c75579b329d80b3eaac27ca3 to your computer and use it in GitHub Desktop.
Save munirwanis/358532b5c75579b329d80b3eaac27ca3 to your computer and use it in GitHub Desktop.
Used to bring all country names directly from NSLocale
//
// LocaleExtension.swift
//
//
// Created by Munir Wanis on 02/11/17.
// Copyright © 2017 Munir Xavier Wanis. All rights reserved.
//
import Foundation
extension Locale {
struct Country {
let code: String
let name: String
}
static func countries() -> [Country] {
var countries = [Country]()
for localeCode in NSLocale.isoCountryCodes {
let currentLocale = NSLocale.current as NSLocale
let countryName = currentLocale.displayName(forKey: NSLocale.Key.countryCode, value: localeCode)!
let countryCode = localeCode
let country = Country(code: countryCode, name: countryName)
countries.append(country)
}
return countries.sorted(by: { $0.name < $1.name })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment