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)")
}
}
在这个代码示例中,有什么方法可以让我的代码以打印的方式运行
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
答案 0 :(得分:1)
试试这段代码
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()
}