NSUserDefaults Error
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_T开发者_运维知识库IME_FLAG];
but sometimes it works, sometimes it does not.
Can you help me ?
just try and call
[defaults synchronize];
after you set the value to NSUserDefaults
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.
精彩评论