For a small system I need the Country Code mapped to the country name (e.g. "GB"-> "United Kingdom"). To accomplish that I read a JSON file and save it to a dictionary using swiftyJSON. Is there a cleaner and better way than I did:
fileprivate func loadNames() {
if let filePath = Bundle.main.path(forResource: "countryNames", ofType: "json") {
if let jsonData = NSData(contentsOfFile: filePath) {
let json = JSON(jsonData)
countryNames = json.dictionaryObject! as NSDictionary
}
}
}
The JSON looks like this:
{
"BD": "Bangladesh",
"BE": "Belgium",
...
}