I'm experiencing an issue when saving & retrieving an int from NSUserDefaults. I am saving to NSUserDefaults using the following code:
int globalRank = 1;
NSUserDefaults *submissionDefaults = [NSUserDefaults standardUserDefaults];
[submissionDefaults setInteger: globalRank forKey:@"globalRankIntForLT"];
NSLog(@"updating %@ as the globalRank in NSUserDefaults",globalRank);
[submissionDefaults synchronize];
This appears to work correctly. In my output I can see:
"updating 1 as the globalRank in NSUserDefaults"
When I retreive the number using the code below:
NSUserDefaults *submissionDefaults = [NSUserDefaults standardUserDefaults];
NSInteger *currentGlobalRank = [submissionDefaults integerForKey:@"globalRankIntForLT"];
int currentGlobalRankInt = currentGlobalRank;
NSLog(@"Retrieved skip int is: %d as nsinteger is: %d",currentGlobalRankInt, currentGlobalRank);
I get output:
"Retrieved skip int is: 4978484032 as nsinteger is: 4978484032"
I later pass this int to another method that returns an error because 4978484032 is bigger than it was expecting.
NSUserDefaults contains an NSInteger but it is coming incorrectly even at that point. What am I doing wrong? Thanks, James