Should I manually save the managedObjectContext file for the NSFetchedResultsController if I change any attribute?

I use NSFetchedResultsController to populate and manage the data source of my tables.

When the user selects a specific row, an action sheet appears, and then the user can change the value for that row:

NSManagedObject *managedObject = [fetchedResultsController objectAtIndexPath:selectedRowIndexPath]; [managedObject setValue:status forKey:@"status"]; 

This works very well, and I can immediately see the changes in the table view. This means that NSFetchedResultsController knows that something has changed and therefore reloads this table. When I stop and leave the application (completely), and then open it again, the change is not saved.

I think NSFetchedResultsConroller will take care of saving the changes.

Do I need to save manually using the following code after each change?

 // Save the context. NSError *error = nil; if (![self.managedObjectContext save:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } 

Or maybe name this code in:

 - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath 
+6
source share
1 answer

You're right. You need to manually save the context in the repository. NSFetchedResultsController captures data from the context, but does not store the data in storage.

+6
source

Source: https://habr.com/ru/post/910701/


All Articles