I have a base class with some variables defined that looks something like:
@interface Foo : NSObject {
SomeObject *baz;
}
@implementation Foo
@synthesize baz;
// ...
@end
@interface Bar : Foo
@end
@implementation Bar
-(void)someMethod {
NSString *foostr = [NSString stringWithFormat:"%@", baz];
}
I actually have a base class with about 30 subclasses.
The issue is that in most of them I can reference the base class' varia开发者_JAVA百科ble bad simply as baz but in a couple of sub-classes I have to explicitly reference bad as self.baz ...
Has anybody else seen this pathology?
If your compiler is set to gcc, there's a bug: A subclass that defines a @property without a corresponding ivar definition (which is perfectly legal) hides any superclass ivars.
Solution: Switch your compiler to LLVM.
(If that solution isn't feasible for some reason, the fallback is what you discovered: Use messaging instead of direct reference.)
精彩评论