我想A通过在B. 由于实例变量默认为@protected,因此访问它们应该没问题。x但是,我在方法中对实例变量所做的更改A不会反映到B,反之亦然。
@interface A : NSObject {
    X *x;
}
- initWithX:(X *)anX;
@end
@implementation A
- initWithX:(X *)anX
{
    assert(anX != nil);
    if (self = [super init]) {
        x = anX;
    }
    assert(self != nil);
    return self;
}
@end
@interface B : A
@end
@implementation B
- initWithX:(X *)anX
{
    assert(anX != nil);
    if (self = [super initWithX:anX]) {
        assert(x != nil);      <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< FAILS
    }
    return self;
}
@end
如何在和x之间共享变量?AB