Last active
December 8, 2017 00:52
-
-
Save munirwanis/358532b5c75579b329d80b3eaac27ca3 to your computer and use it in GitHub Desktop.
Used to bring all country names directly from NSLocale
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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