I set up my viewcontrollerA as a singleton. In a viewcontrollerA.h I have:
@property (nonatomic, assign) NSNumber* showCommentOrCreate;
In viewcontrollerB.m I have:
PhotoViewController* sharedSingleton = [PhotoViewController sharedManager];
sharedSingleton.showCommentOrCreate = [NSNumber numberWithInt:2];
In my viewcontrollerB.m I have:
PhotoViewController* sharedSingleton = [PhotoViewController sharedManager];
NSLog(@"num %ld", (long)sharedSingleton.showCommentOrCreate);
The problem is that for whatever value I set in this way [NSNumber numberWithInt:whole number], I always get a number which isn’t the number I have set:
e.g. 2013-01-24 19:42:24.936 Splash-it[870:907] num 475536752
Does anyone know why?
Because you’re printing the pointer to the
NSNumberobject, and not the integer value stored in it.