How to dispatch_group_wait for dispatch_group_async inside an asynchronous block

六眼飞鱼酱① 提交于 2019-12-01 08:57:05

Think of this method as a static counter available to threads, so when you enter a group the counter increments, and when that block returns, decrements...

When that counter is 0, it will call a block to invoke

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_group_t group = dispatch_group_create();

while(someCondition)
{
    dispatch_group_enter(group);
   [SomeClassThatLoadsOffTheInternet getMyImages:^{

        // do something with these.
        dispatch_group_leave(group);

    });
}

dispatch_group_notify(group, queue, ^{
    // do something when all images have loaded
});

Is that what you were thinking of?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!