Skip to content

Instantly share code, notes, and snippets.

@olivaresf
Created September 28, 2020 05:52
Show Gist options
  • Save olivaresf/39dff86a540067e857db87b3a197f5e8 to your computer and use it in GitHub Desktop.
Save olivaresf/39dff86a540067e857db87b3a197f5e8 to your computer and use it in GitHub Desktop.
func setup() {
// Loading a JSON with our country list.
// If our data is invalid, make sure to catch it early in the development process.
let frameworkBundle = Bundle(for: type(of: self))
let defaultCountriesJSONPath = frameworkBundle.path(forResource: "SwiftCountryPicker.bundle/Data/countryCodes",
ofType: "json")!
let defaultCountriesJSONData = try! Data(contentsOf: URL(fileURLWithPath: defaultCountriesJSONPath))
let defaultCountriesDictionaries = try! JSONSerialization.jsonObject(with: defaultCountriesJSONData,
options: .allowFragments) as! NSArray
countries = defaultCountriesDictionaries.map { Country(dictionary: $0 as! NSDictionary) }
if let code = Locale.current.languageCode {
self.selectedLocale = Locale(identifier: code)
}
super.dataSource = self
super.delegate = self
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment