Skip to content

Instantly share code, notes, and snippets.

@alexnodejs
Created May 14, 2015 00:00
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexnodejs/2536ec551b8bad9bc926 to your computer and use it in GitHub Desktop.
Save alexnodejs/2536ec551b8bad9bc926 to your computer and use it in GitHub Desktop.
Wait for multiple async calls and do something after that (Swift)
let url = NSURL(string: "https://www.google.net")
let request = NSURLRequest(URL: url!)
let group = dispatch_group_create()
for index in 1...100 {
dispatch_group_enter(group)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {(response, data, error) in
println("\(index) complete")
dispatch_group_leave(group)
}
}
dispatch_group_notify(group, dispatch_get_main_queue()) {
println("All tasks are done")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment