开发者

Saving selected date and time into a plist

I would like to know h开发者_如何转开发ow to save a selected date and time from a date picker into a plist.


NSMutableArray *userArray = [[NSMutableArray alloc] initWithContentsOfFile:plistPath];
NSMutableDictionary *dict = [userArray objectAtIndex:0];
NSDate *date = [NSDate date];
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"MM/dd/yyy hh:mm a"];         
[dict setObject:[dateformatter stringFromDate:date] forKey:@"LastLocalDataUpdate"];
[userArray writeToFile:plistPath atomically:YES];


NSUserDefaults is good enough for what you're trying to do:

NSDate *theDate = [NSDate date];
[[NSUserDefaults standardUserDefaults] setObject:theDate forKey:@"Date"];


NSUserDefaults will do it just nicely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜