Reputation: 2186
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.
Upvotes: 12
Views: 5223
Reputation: 5290
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.
Upvotes: 0
Reputation: 46598
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);
Upvotes: 11