1
votes


I'm trying to build a RSS reader, but I'm having trouble with saving the date to CoreData.

NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd"];
    NSDate *dt = [df dateFromString: [article valueForKey:@"pubDate"]];
    [df release];

When I save everything, the date field in the database is null.
Please help!

2

2 Answers

1
votes

pubDate is an RFC822 format field. The date format you're giving to the NSDateFormatter seems inappropiate.

Have a look at this question for parsing RFC822 on an iPhone.

1
votes

Log out the date and make sure you are saving the core data object correctly. You can try the following save for a detailed error message, if any.

    NSError* error;
    if (![managedObjectContext save:&error]) {
        NSLog(@"Failed to save to data store: %@", [error localizedDescription]);
        NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
        if(detailedErrors != nil && [detailedErrors count] > 0) {
            for(NSError* detailedError in detailedErrors) {
                NSLog(@"  DetailedError: %@", [detailedError userInfo]);
            }
        } else
            NSLog(@"  %@", [error userInfo]);
    }