Created
September 28, 2020 05:52
-
-
Save olivaresf/39dff86a540067e857db87b3a197f5e8 to your computer and use it in GitHub Desktop.
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
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