Reputation: 1
I use NSUserDefaults to save message:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDate *nowTime = [NSDate date];
NSString *strNowTime = [nowTime description];
strNowTime = [strNowTime substringToIndex:19];
NSLog(@"%@",strNowTime);
[defaults setValue:strNowTime forKey:KEY_UPDATE_TIME_FLAG];
but sometimes it works, sometimes it does not.
Can you help me ?
Upvotes: 0
Views: 382
Reputation: 34296
just try and call
[defaults synchronize];
after you set the value to NSUserDefaults
Upvotes: 3
Reputation: 125037
How can you tell that it doesn't work? Perhaps the problem is with the code that reads the value back from defaults. The code you posted looks okay, although I'd suggest using NSDateFormatter to create a string from a date rather than -description. -description is really best used for debugging and not much else.
Upvotes: 0