我在班级中有一个私人BOOL
@property (nonatomic, assign) BOOL myBool;
我想覆盖getter和setter,以便我可以同步它,或者将它发送到一个串行队列。
- (BOOL)myBool
{
__block BOOL test = NO;
dispatch_sync(self.shouldShowBannerQueue, ^{
test = _myBool; //This does not work. I get an error "Use of undeclared _myBool"
});
return test;
}
出于同样的原因,我无法覆盖setter。我无法直接访问_myBool。
答案 0 :(得分:0)
如果要定义访问器方法,则不会发生隐式综合,也不会有_myBool
变量。但您可以简单地将一个实例变量添加到类中,并使用它来支持访问器方法。