views:

89

answers:

0

Hi. I'm using Core Data to fetch news from the memory and I want to modify the unread attribute after the news is read.

Code:

    //method called from within a UITableViewController
    -(void) didCloseNews:(NSIndexPath*)indexPath{
     //get the newsItem - NewsItem subclasses NSManagedObject
     NewsItem* newsItem = [self.fetchedResultsController objectAtIndexPath:newsNumber];
     //change the value
     NSLog(@" %d ",[(NSNumber*)[newsItem valueForKey:@"unread"] intValue]); //prints 1
     [newsItem setValue:[NSNumber numberWithInt:0] forKey:@"unread"];
     NSLog(@" %d ",[(NSNumber*)[newsItem valueForKey:@"unread"] intValue]); //prints 0
     NSLog(@" %d ",[newsItem isUpdated]);//prints 0
     //save the context
     NSManagedObjectContext *context = [self.logic.newsReaderAppDelegate managedObjectContext];
        NSError *error = nil;
        if (![context save:&error]) {
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            abort();
        }
    }

I've tested all objects, none of them is nil. The changes to the unread attribute are visible in the application but they revert next time I launch it.

Why does [newsItem isUpdated] print FALSE?

update: I solved the problem by removing the NewsItem class and dealing only with NSManagedObject objects instead. Anyway it would be good to find out what was wrong.