在 C/Obj-C 中,我们做一个 typedef 就像这样 typedef int MYINT;
很清楚。
为 block 做 typedef -typedef void (^MyBlock) (int a);
现在,我们可以使用MyBlock
了。
不应该是类似于-typedef void (^MyBlock) (int a) MyBlock;
类似于#define
吗?
语法如何工作?
最佳答案
见 Declaring a Block Reference在“ block 编程主题”中:
Block variables hold references to blocks. You declare them using syntax similar to that you use to declare a pointer to a function, except that you use ^ instead of *.
所以
typedef void (^myBlock) (int a);
使用与
相同的语法定义 block 的类型 typedef void (*myFunc) (int a);
声明一个函数指针。
参见例如Understanding typedefs for function pointers in C有关函数指针的更多信息。
https://stackoverflow.com/questions/15310880/