Reputation: 454
I have to make a number of async requests to a server (let's say 20) and I need to wait for all them to finish (being successful or not) to trigger an action. I want to know if there's an elegant way of keeping a reference to all of them without keeping a variable in the parent's scope, i.e not like:
var numberOfCalls = 10
for i in 1...20 {
Alamofire.request(.GET, url) { response in
numberOfCalls--
if numberOfCalls == 0 {
// do something
}
}
}
I'm using Alamofire, Swift 2, xcode 7
Upvotes: 0
Views: 591
Reputation: 454
I finally wrapped my head around GCD handling multiple concurrent tasks on this post Dispatch Groups suggested by @GoodSp33d
Upvotes: 1