Skip to content

Instantly share code, notes, and snippets.

@jessedc
Created September 1, 2016 06:26
Show Gist options
  • Save jessedc/ebd20bfc3bd6afd4b0cc13f67bbcc0aa to your computer and use it in GitHub Desktop.
Save jessedc/ebd20bfc3bd6afd4b0cc13f67bbcc0aa to your computer and use it in GitHub Desktop.
Fetch all of the Countries supported in UIKit
//: 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