0

I want to create a method which run's a user's provided block of code, making use of dispatch groups, and has the implementation as follows:

dispatch_group_enter(self.group);
block(^ {
    dispatch_group_leave(self.group);
    if (completion) {
        completion();
    }
});

dispatch_group_wait(self.group, DISPATCH_TIME_FOREVER);

I'm not sure how to write the name of this method, however.

It'd be something similar to:

- (void)performBlock:(void(^)())block;

But then remember that the block provided has to have its own callback for completion.

The implementation would be something like this:

[object performBlock:^(void(^)() completion) {
    //Do stuff
    completion();
}];
Andrew
  • 7,693
  • 11
  • 43
  • 81

1 Answers1

0

Have I misunderstood the question if I suggest?

- (void)performBlock:(void(^)())block completion:(void(^)())completion;

If I have not misunderstood I would recommend to add support for error handling

- (void)performBlock:(void(^)())block completion:(void(^)(NSError *err))completion;
Lev Landau
  • 788
  • 3
  • 16