Last active
August 5, 2023 10:50
-
-
Save kaloprominat/fdca1a4994c9d7f14a2e to your computer and use it in GitHub Desktop.
xcode objective-c GCD dispatch group wait example
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
//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