Created
September 1, 2016 06:26
-
-
Save jessedc/ebd20bfc3bd6afd4b0cc13f67bbcc0aa to your computer and use it in GitHub Desktop.
Fetch all of the Countries supported in UIKit
This file contains hidden or 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
//: Playground - noun: a place where people can play | |
import UIKit | |
// If you're in a playground, you need to swizzle current locale | |
extension NSLocale { | |
class func jc_currentLocale() -> NSLocale { | |
return NSLocale.init(localeIdentifier: "en_AU") | |
} | |
} | |
let method = class_getClassMethod(NSLocale.self, #selector(NSLocale.currentLocale)) | |
let swizzledMethod = class_getClassMethod(NSLocale.self, #selector(NSLocale.jc_currentLocale)) | |
method_exchangeImplementations(method, swizzledMethod) | |
let currentLocale = NSLocale.currentLocale() | |
let countryArray = NSLocale.ISOCountryCodes() | |
.flatMap { currentLocale.displayNameForKey(NSLocaleCountryCode, value: $0) } | |
.sort { $0.localizedCompare($1) == .OrderedAscending } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment