Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kaloprominat/fdca1a4994c9d7f14a2e to your computer and use it in GitHub Desktop.
Save kaloprominat/fdca1a4994c9d7f14a2e to your computer and use it in GitHub Desktop.
xcode objective-c GCD dispatch group wait example
//first
dispatch_async(queue, ^{
dispatch_group_t group1 = dispatch_group_create();
// Tasks goes here
for (NSInteger i = 0; i < 3; i++) {
dispatch_group_enter(group1);
someTaskWithCompletitionBlock:^() {
dispatch_group_leave(group1);
};
}
dispatch_group_wait(group1, DISPATCH_TIME_FOREVER);
dispatch_async(dispatch_get_main_queue(), ^{
// Perform completition block
});
});
//second
dispatch_group_t group2 = dispatch_group_create();
for (NSInteger i = 0; i < 3; i++) {
dispatch_group_enter(group2);
someTaskWithCompletitionBlock:^() {
dispatch_group_leave(group2);
};
}
dispatch_group_notify(group2, dispatch_get_main_queue(), ^{
// Perform completition block
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment