Swift How To Wait In A Loop

[Solved] Swift How To Wait In A Loop | Swift - Code Explorer | yomemimo.com
Question : swift how to wait in a loop

Answered by : determined-dragonfly-ivgoww68zu0d

override func viewDidLoad() { super.viewDidLoad() let myGroup = DispatchGroup() for i in 0 ..< 5 { myGroup.enter() Alamofire.request("https://httpbin.org/get", parameters: ["foo": "bar"]).responseJSON { response in print("Finished request \(i)") myGroup.leave() } } myGroup.notify(queue: .main) { print("Finished all requests.") }
}

Source : https://stackoverflow.com/questions/35906568/wait-until-swift-for-loop-with-asynchronous-network-requests-finishes-executing | Last Update : Thu, 12 Nov 20

Answers related to swift how to wait in a loop

Code Explorer Popular Question For Swift