Question

Is it possible to have a static variable of a "block type"?

I have a class that only does stuff in static methods. Upon execution of those methods i'm calling statusChangedBlock. Just for that i create a shared instance of the class, and use its single block property. I wonder if it's possible to have a static block variable; so i wouldn't have to create a instance with a single property, just for notifying that my status changed.

I know there is an option of NSNotification, but i don't like using it, with some rare exceptions.

...this question somehow sounds stupid, i can't tell why. I hope someone points that out.

Was it helpful?

Solution

to declare a static variable of block type

typedef ReturnType (^MyBlockType)(ArgumentType, ArgumentType2);
static MyBlockType myblock;
static MyBlockType myblock2;

or

static ReturnType (^myblock)(ArgumentType, ArgumentType2);

OTHER TIPS

A block type variable is actually a pointer, similar to an object. You can have a static block variable, but you must assign its value at runtime, perhaps using a dispatch_once block.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top