My issue is simple. I have 3 tasks, one is triggered by an NSNotification. How to I wait for all task to be completed before proceeding.
So far, I tried using dispatch group but can't find a way to add the task triggered by NSNotification. (I tried adding the dispatch command within the method triggered by the NSNotification, but if the notification comes after task 1 and 2, it's too late to add to the group as it is already completed.)
_asyncDispatch = dispatch_group_create();
dispatch_group_async(_asyncDispatch,dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {
[self doTask1];
});
dispatch_group_async(_asyncDispatch,dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {
[self doTask2];
});
dispatch_group_notify(_asyncDispatch,dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {
// We're done!
});
Thanks @Sega-Zero for your guidance. Here is the solution I implemented.
And then, in the method triggered by the NSNotification
Voila. Thanks to all.