Understanding inheritance of Objective-C instance variables -


i extend method of superclass a new functionality subclassing in b. since instance variables default @protected, accessing them should fine. however, changes instance variable x make in method of a not reflected b , vice versa.

@interface : nsobject {     x *x; }  - initwithx:(x *)anx;  @end  @implementation  - initwithx:(x *)anx {     assert(anx != nil);     if (self = [super init]) {         x = anx;     }     assert(self != nil);     return self; }  @end  @interface b :  @end  @implementation b  - initwithx:(x *)anx {     assert(anx != nil);     if (self = [super initwithx:anx]) {         assert(x != nil);      <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< fails     }     return self; }  @end 

how can share variable x between a , b?

check code yet again. , yet again. code must working, really... it's kind of basic relationship between inherited , parent interface , should operate expect.

it must in code you've stripped sample.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -