I have a variable (var1) that gets set in my AppDelegate. I have another class MyClass where I'd like to retrieve the variable from AppDelegate. I can set the variable (var2) defined in MyClass just fine:
AppDelegate:
- (void)setVariable {
var1 = @"TEST";
MyClass *setVar = [[MyClass alloc] init];
setVar.var2 = var1;
NSLog(@"var2: %@",setVar.var2); // Outputs TEST
}
When I try to get the variable in MyClass it's Null:
MyClass
- (void)getVariable {
AppDelegate *getVar = [[AppDelegate alloc] init];
var2 = getVar.var1;
NSLog(@"var2: %@",var2); // Outputs NULL
}
It works if I also include [getVar setVariable];
but that's not exactly what I want to do, as it would be setting the variable as a static value. I'm trying to get the variable as it was set previously in AppDelegate.