In my AppDelegate, I have
#import <UIKit/UIKit.h>
#import "CustomerProfile.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) int x;
@end
At class B, I do
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
appDelegate.x = 5;
Then at Class C, I do
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
appDelegate.x = 4;
Eventually, at class D I print out the result of x and x = 5. Should x be 4.
It is confusing me. Please advice me on this issue.
Thanks
In your App delegate method your property x is set to strong (aka retain), you have to set to assign, a int var can’t be retained because its not a object:
Second, you have to import the header of your appDelegate (in your B,C,D Classes)
set your appDelegate instance:
then set your x var to the desired value
I tested this in one of my projects and works.