I would like to run an Alamofire request that is using the result of a previous Alamofire request as a parameter. To make it simple:
//Code1
Alamofire.request("URL", method: HTTPMethod.post, parameters: ["id": id as NSString)], encoding: URLEncoding.httpBody).response(completionHandler: { (response) in
let json = response.data
do {
print("This should be First")
let data = try JSON(data: json!)
let alllastmessages = data["Messages"].arrayValue
for i in 0..<alllastmessages.count {
self.List.append(alllastmessages[i]["message"].stringValue)
}}
catch _{}
})
//End Code1
//Code2
print("This should be Last")
for i in 0..<List.count {
Alamofire.request("URL2", method: .post , parameters: ["id": id as NSString] , encoding: URLEncoding.httpBody).response(completionHandler: { (response) in
//Do Something
})
self.tableView.reloadData()
}
//End Code2
(This code is simplified, I'm just looking for a way to make Code1 run before Code2)