Created
May 14, 2015 00:00
-
-
Save alexnodejs/2536ec551b8bad9bc926 to your computer and use it in GitHub Desktop.
Wait for multiple async calls and do something after that (Swift)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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