Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return Objective-C block from C function

What is the syntax to declare a C function that returns an Objective-C block? Is it possible?

I thought it should be something like

(void (^)(void)) myFunctionReturningABlock();

but that won't compile.

like image 608
Nick Moore Avatar asked Nov 28 '11 13:11

Nick Moore


1 Answers

The syntax for your function is slightly incorrect.

As I understand it, you should define your block as a type which you can use as the return type for your function like this:

typedef void(^MyAwesomeBlock)(void);

MyAwesomeBlock blockFunction()
{
    MyAwesomeBlock block = ^{
        //some code;
    };

    return block;
}
like image 78
Jasarien Avatar answered Oct 21 '22 15:10

Jasarien