如何获得块的名称?

Kun*_* Hu 1 objective-c objective-c-blocks

我们有

typedef id(^func)(id);
func read_file = ^(NSString *path_to_file) {
     return [NSString stringWithContentsOfFile:path_to_file encoding:NSUTF8StringEncoding error:NULL];
};
Run Code Online (Sandbox Code Playgroud)

我想知道如果我在一些函数调用中将它作为参数传递,我们怎么能得到这个块的名字?例如,

fileOperator(read_file); // I want to print the block's name in this function.
Run Code Online (Sandbox Code Playgroud)

谢谢.

Cal*_*leb 6

我想知道如果我在一些函数调用中将它作为参数传递,我们怎么能得到这个块的名字?

您无法获取作为参数传递的块的名称,只能获取int作为参数传递的变量的名称.该名称不是块的一部分...该名称与包含该块的变量相关联.

假设您已将块作为参数传递,则应使用参数名称来引用块,就像使用参数名称来引用int传递给函数或方法的整数值一样.