Skip to content

Instantly share code, notes, and snippets.

@alfian0
Created December 10, 2016 17:11
Show Gist options
  • Save alfian0/68c2561a6c54cfaf723228e0cce54083 to your computer and use it in GitHub Desktop.
Save alfian0/68c2561a6c54cfaf723228e0cce54083 to your computer and use it in GitHub Desktop.
Just Simple Merging API Call in Swift
func mergeAPICall() {
let group = dispatch_group_create()
dispatch_group_enter(group)
/***
Call your method for each endpoint after dispatch_group_enter(group)
*/
func fetchEventList(success: { (eventList) in
/***
Add dispatch_group_leave(group) if API Call return success or error
*/
dispatch_group_leave(group)
}) { (error) in
dispatch_group_leave(group)
}
func fetcMovieList(success: { (eventList) in
/***
Add dispatch_group_leave(group) if API Call return success or error
*/
dispatch_group_leave(group)
}) { (error) in
dispatch_group_leave(group)
}
dispatch_group_notify(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) {
dispatch_async(dispatch_get_main_queue(), {
/***
Do something if All API Call done
Your code Here
*/
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment