Reputation: 989
for i in 0 ..< 5 {
print("Request Number" ,i)
Alamofire.request("https://httpbin.org/get", parameters: ["foo": "bar"]).responseJSON { response in
print("Finished request \(i)")
}
}
In this sample of code, is there any way I can get the above code run in a way such that it prints
Request Number 0
Finished request 0
Request Number 1
Finished request 1
Request Number 2
Finished request 2
Request Number 3
Finished request 3
Request Number 4
Finished request 4
Upvotes: 2
Views: 769
Reputation: 1821
try this code
for i in 0 ..< 5 {
print("Request Number" ,i)
let runLoop = CFRunLoopGetCurrent()
Alamofire.request("https://httpbin.org/get", parameters: ["foo": "bar"]).responseJSON { response in
print("Finished request \(i)")
CFRunLoopStop(runLoop)
}
CFRunLoopRun()
}
Upvotes: 2