Objects being reset to NULL after being set to a non-NULL value
I have two Objective-C classes that communicate data with each other by
passing variables through method parameters. For example I might call a
method that will pass a variable:
ClassX *x = [[ClassX alloc] init];
[x passThisParameter:i];
The variable is successfully received by ClassX inside of the
passThisParameter method. I can confirm this with breakpoints and log
output:
- (void)passThisParameter:(id)object {
self.globalVariable = object;
NSLog(@"Object: %@", self.globalVariable); // In the log I can see
that globalVariable has the same value as object does.
}
However when I try to use globalVariable outside of the above scope (ex.
in another method, but in the same class) it always shows up as NULL. Why
is my globalVariable getting reset to NULL?
I've also tried to setup the variable in a variety of ways in my class
definition / header and as an implementation variable:
@property (retain) id globalVariable
@property (strong) id globalVariable
@property (assign) id globalVariable
@property (nonatomic, strong) id globalVariable
Any ideas on why this globalVariable gets reset to NULL? I can't figure it
out and couldn't find much on Google. Please forgive me if some of my
programming terms are incorrect.