Implementing a method taking a block to use as callback Implementing a method taking a block to use as callback ios ios

Implementing a method taking a block to use as callback


You can call a block like a regular function:

BOOL finished = ...;if (completion) {    completion(finished);}

So that means implementing a complete block function using your example would look like this:

+ (void)myMethod:(UIView *)exampleView completion:(void (^)(BOOL finished))completion {    if (completion) {        completion(finished);    }}


I would highly recommend that you read up on Blocks to understand what is happening.


If you're specially looking for a doc, to create custom method using blocks, then the following link is the one which explains almost everything about it. :)

http://developer.apple.com/library/ios/documentation/cocoa/Conceptual/Blocks/Articles/bxUsing.html

I happen to answer quite a same question recently, have a look at this: Declare a block method parameter without using a typedef