I could use some help. After a few frustrating days of trial and error, I'm getting inconsistent results writing preferences to NSUserDefaults.
Here are the consecutive lines of code:
NSLog(@"startTimer(): End Time defaults: %f\n", [defaults floatForKey:kEndTimeKey]);
NSLog(@"startTimer(): new End Time: %f\n", endTime);
[defaults setFloat:endTime forKey:kEndTimeKey];
[defaults synchronize];
NSLog(@"startTimer(): stored EndTimeKey: %f\n", [defaults floatForKey:kEndTimeKey]);
kEndTimeKey is a constant string.
As you can see I log the current value for the key, then I log the value I intend to store, synchronize, then re-read the stored value. Seems simple to me, but here's the debugger output:
2009-07-22 22:05:43.263 TimerTest3[1584:207] startTimer(): End Time defaults: 0.000000
2009-07-22 22:05:43.266 TimerTest3[1584:207] startTimer(): new End Time: 270018630.916571
2009-07-22 22:05:43.287 TimerTest3[1584:207] startTimer(): stored EndTimeKey: 270018624.000000
I see the original value 0, the intended value ending in 571, and the value read from the cache which is 6 seconds off.
I'm not sure where the new default came from. Any ideas? I get similar behavior on the device and on the simulator.
Thanks Brad