在ios应用中一个单例模式:
void (^ myBlock)() = ^(){ [self doStuff]; };
然后就得到这样的错误:
use of undeclared identifier self
doStuff
是单例模式的方法。假如在其他方法中声明这个block,Xcode运行正常。
请各位前辈帮我解释一下原因,谢谢
在ios应用中一个单例模式:
void (^ myBlock)() = ^(){ [self doStuff]; };
然后就得到这样的错误:
use of undeclared identifier self
doStuff
是单例模式的方法。假如在其他方法中声明这个block,Xcode运行正常。
请各位前辈帮我解释一下原因,谢谢
在界面中定义block,然后在@implementation文件中实例化选中的方法:
@interface YourClass {
void (^ myBlock)();
}
@implementation YourClass
- (void)yourMethod {
myBlock = ^(){ [self doStuff]; };
}
@end