具有自动合成属性的子类中的_underbar变量用法?

时间:2013-02-13 22:20:02

标签: objective-c

今天在Xcode 4.6中进入今天,它让我感到惊讶。我正在使用自动合成属性(但手动合成没有区别)。

@interface TestA : NSObject
@property (strong) id foo;
@end

#import "TestA.h"
@interface TestB : TestA
- (id)initWithFoo:(id)foo;
@end

@implementation TestB
- (id)initWithFoo:(id)foo
{
    self = [super init];
    if (self)
    {
        _foo = foo; // Xcode says _foo is not defined.
        //self.foo = foo; // This does work though.
    }
    return self;
}
@end

我可以在_foo的实施中访问TestA,但不在TestB中。我可以通过在id _userInfo中将TestA.h作为ivar声明来解决这个问题,但我认为不必这样做。这里发生了什么?

0 个答案:

没有答案