I have a main function (buttonPressed), that should print out a Jsonfile.
func buttonPressed {
var jasonFile = JSON()
jasonFile = getInfo(parA: 5, parB: 10) //1. takes some time
print(jsonFile) //prints before the JSON is get from the internet
}
To get the Jsonfile I made a function, which accepts parameters and downloads the information and returns the Jsonfile. Of course this takes quite a while so the code in myFunction is already executed even though it haven't received the data.
(I am using Alamofire and SwiftyJSON)
func getInfo(parA: Int, parB: Int) -> [Int] {
var thisJsonFile = JSON()
Alamofire.request(url, method: .get).validate().responseJSON { response in
switch response.result {
case .success(let value):
let json = JSON(value)
thisJsonFile = json
case .failure(let error):
print(error)
}
}
return thisJsonFile //returns an empty File
}
Is there a way to return the JsonFile after it has been finished loading?