Search code examples
objective-ciosplistuidatepicker

Saving selected date and time into a plist


I would like to know how to save a selected date and time from a date picker into a plist.


Solution

  • 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];