I'm using an NSFetchedResultsController to populate and manage my tables data source.
When a user picks a certain row, an actionsheet pops up and then lets the user change a value for that row:
NSManagedObject *managedObject = [fetchedResultsController objectAtIndexPath:selectedRowIndexPath];
[managedObject setValue:status forKey:@"status"];
This works really well and I can see the changes immediately in the tableview. This means that the NSFetchedResultsController knows something is changed and therefore reloads that tableviewcell. When I stop and quit my app (completely) then reopen it, the change is not saved.
I would think NSFetchedResultsConroller takes care of saving changes.
Do I need to save manually using the following code after every change?
// Save the context.
NSError *error = nil;
if (![self.managedObjectContext save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
Or maybe call this code in:
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
You are correct. You need to manually save the context to the store. NSFetchedResultsController grabs data from the context, but does not save data to the store.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With