Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static block variable in Objective-C

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.

like image 821
user1244109 Avatar asked Nov 22 '13 00:11

user1244109


1 Answers

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);
like image 125
Bryan Chen Avatar answered Sep 18 '22 11:09

Bryan Chen