I work with Alamofire and SwiftyJSON and have function:
func getCitiesFromServer(){
Alamofire.request("mysite", method: .get, encoding: JSONEncoding.default, headers: nil)
.responseJSON { response in
switch response.result {
case .success:
var json = JSON(response.result.value!)
for i in 0..<json["cities"].count {
self.dictOfCities[json["cities"][i]["id"].int!] = json["cities"][i]["name"].string
}
case .failure(let error):
print(error)
}
}
}
And I'd like to work with dictOfCities when I create tableView, but how return dictOfCities in getCitiesFromServer()? I try print(dictOfCities) at the end of getCitiesFromServer(), but see only [:], but in part case .success: I see good key-value.