Objective-C Syntax for a Block that has a Block as a Parameter?

I'm not sure this is even possible (and I'm sure there will be questions as to why) but I'm curious how one could define a block that takes a block as a parameter? For instance...

MyFunctionWithSuccess:(void(^)((void(^)(NSString* value))blockAsParameter)success

This of course doesn't work.

The only thing I could find is on StackOverflow but I think in this case it returns a block. Regardless the syntax throws a compiler error..

StackOverflow - Syntax to define a Block that takes a Block and returns a Block in Objective-C

There it says to define it as :

void (^(^complexBlock)(void (^)(void)))(void)

However this throws a "Type-id cannot have a name" which it complains about the ^complexBlock part.

Again it just may be that this is not possible and bad to do. However I'd like to confirm that it is or isn't.

Quinn’s secret sauce when dealing with C function pointers (and now blocks, replacing the * with ^) is to lean on typedefs. For example:

@import Foundation;

typedef void (^CompletionHandler)(void);
typedef void (^WorkerBlockThatTakesACompletionHandler)(CompletionHandler);

int main(int argc, char **argv) {
    #pragma unused(argc)
    #pragma unused(argv)
    WorkerBlockThatTakesACompletionHandler w = ^(CompletionHandler ch) {
        NSLog(@"work will start");
        sleep(1);
        NSLog(@"work did finish");
        ch();
    };
    w(^{
        NSLog(@"completion");
    });

    return EXIT_SUCCESS;
}

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Objective-C Syntax for a Block that has a Block as a Parameter?
 
 
Q