我在类中有一个静态块变量。如何声明属性或实例选择器以将该块返回或发送给调用者?
这是我的静态阻止:
static NSResultComparison(^myBlock)(id obj1, id obj2);
答案 0 :(得分:5)
最好typedef
你的阻止。
//interface.h
typedef NSResultComparison (^ComparisonBlock)(id obj1, id obj2);
@interface ...
...
-(ComparisonBlock) getComparisonBlock;
@end
//implementation.m
//Here is your static block implementation
static ComparisonBlock myStaticBlock = ^(id obj1, id obj2)
{
...
return result;
};
@implementation ...
-(ComparisonBlock)getComparisonBlock
{
return myStaticBlock;
}
@end