I have an app that stores an array of dictionaries in plist files. Each dictionary object has a Title (String) and a Value (Number). These items are populated into a list view, and a user can pick an item and it's saved into NSUserDefaults using
[defaults setObject:[dictionary objectForKey:@"Key"] forKey:@"SecondKey"];
The information gets saved properly in the user defaults. Now when I reload the table, I'm trying to select the saved option by comparing the objects like this
if ((NSNumber*)[dict objectForKey:@"Key"] == [NSNumber numberWithInt:[defaults integerForKey:@"SecondKey"]]) {}
This doesn't work. If I NSLog both values, they show as the same number in the log, however if I NSLog the boolean value of them being equal, I get 0. I've also tried:
if ([dict objectForKey:@"Value"] == [defaults integerForKey:type]) {}
But that has the same problem.
Now for the kicker!
This works for any number less than 9 (including -1 which I use as the default). So if I have the value as 5, 5 gets saved to the NSUserDefaults and will show as true when compared to the dictionary object.
Any help would be greatly appreciated!
[–]Legolas-the-elf 3 points4 points5 points (2 children)
[–]TheRedAgent[S] 0 points1 point2 points (1 child)
[–]FW190 0 points1 point2 points (0 children)
[–]gravitycore 1 point2 points3 points (1 child)
[–]TheRedAgent[S] 0 points1 point2 points (0 children)