Skip to content

Instantly share code, notes, and snippets.

@arvindhsukumar
Last active April 7, 2016 15:15
Show Gist options
  • Save arvindhsukumar/fb03265426e10a93e4e5612b9875f607 to your computer and use it in GitHub Desktop.
Save arvindhsukumar/fb03265426e10a93e4e5612b9875f607 to your computer and use it in GitHub Desktop.
Introduction to dispatch_group
func asyncFunctionA(){
let urlRequest: NSURLRequest = ...
let task = self.session?.dataTaskWithRequest(urlRequest, completionHandler: {
(data:NSData?, response:NSURLResponse?, error:NSError?) in
self.taskAComplete = true
self.checkResults()
})
}
func asyncFunctionB(){
let urlRequest: NSURLRequest = ...
let task = self.session?.dataTaskWithRequest(urlRequest, completionHandler: {
(data:NSData?, response:NSURLResponse?, error:NSError?) in
self.taskBComplete = true
self.checkResults()
})
}
func checkResults(){
// Why does this function have to be called twice?!
if taskAComplete && taskBComplete {
//Handle Result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment