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.
精彩评论