objective c - Objects being reset to NULL after being set to a non-NULL value -
i have 2 objective-c classes communicate data each other passing variables through method parameters. example might call method pass variable:
classx *x = [[classx alloc] init]; [x passthisparameter:i]; the variable received classx inside of passthisparameter method. can confirm breakpoints , log output:
- (void)passthisparameter:(id)object { self.classvariable = object; nslog(@"object: %@", self.classvariable); // in log can see classvariable has same value object does. } however when try use classvariable outside of above scope (ex. in method, in same class) shows null. why classvariable getting reset null? here how retrieveing variable later:
- (void)anothermethodfromclassx { nslog(@"class variable: %@", self.classvariable); // null though variable never used anywhere else (except when it's set in method above) } i've tried setup variable in variety of ways in class definition / header , in implementation:
@property (retain) id classvariable@property (strong) id classvariable@property (assign) id classvariable@property (nonatomic, strong) id classvariable
any ideas on why classvariable gets reset null? can't figure out , couldn't find on google. please forgive me if of programming terms incorrect.
edit: using arc, not mrc.
edit: possible classx reallocated , reinitialized after set classvariable reset null? reloaded in ui...
edit: here's classx , classz relevant code available online.
all of @property variants instance variables, value you're setting set onto instance, not class. so, when nothing retain x , gets destroyed arc value goes it. next time create new instance of classx it's clean , fresh value nil. solution retain x , reuse instead of allowing destroyed (and little research class , instance variables).
Comments
Post a Comment