I am using this function in order to get a JSON in another function :
func getData(myUrl : String) -> JSON{
var jsonFromAPI : JSON = [:]
Alamofire.request(.GET, myUrl).responseJSON { (request, response, result) -> Void in
switch result{
case .Success(let data):
jsonFromAPI = JSON(data)
print("json filled")
case .Failure(_, let errorType):
print((errorType as NSError).localizedDescription)
}
}
return jsonFromAPI
}
When I build the code, the function returns an empty JSON as I initialized it, and a few moments later the lane "json filled" appears. I obviously want the json filled to be returned, not the empty one ! How can I correct this problem ? Thanks in advance !