Waiting for multiple blocks to finish

后端 未结 5 648
被撕碎了的回忆
被撕碎了的回忆 2020-12-28 09:33

I have those methods to retrieve some object information from the internet:

- (void)downloadAppInfo:(void(^)())success
                failure:(void(^)(NSErr         


        
5条回答
  •  醉话见心
    2020-12-28 09:54

    Here is my solution without any dispatch_group.

    +(void)doStuffWithCompletion:(void (^)(void))completion{
        __block NSInteger stuffRemaining = 3;
    
        void (^dataCompletionBlock)(void) = ^void(void) {
            stuffRemaining--;
    
            if (!stuffRemaining) {
                completion();
            }
        };
    
        for (NSInteger i = stuffRemaining-1; i > 0; i--) {
            [self doOtherStuffWithParams:nil completion:^() {
                dataCompletionBlock();
            }];
        }
    }
    

提交回复
热议问题