Reputation: 49047
How do I update Core Data entities, what actions are needed? I have a Store
with one-to-many relationship to Product
. When I do a change to the products, remove one or add, do I need to do anything then such as invoking some methods? Or do I just edit products and leave them alone and then they are saved to persistent store when the user quits the application? Is that the normal way?
Upvotes: 0
Views: 951
Reputation: 7344
You have to save them to be persistant - see Managed Object Context in the Core Data Programming Guide from Apple:
Unless you actually save those changes, however, the persistent store remains unaltered.
so here is the code
NSError *error = nil;
BOOL savedSuccessfully = [self.managedObjectContext save:&error];
if (!savedSuccessfully) {
NSLog(@"Could not save date change! Reason : %@", [error localizedDescription]);
}
You should save often and not only when exiting the app. See this answer: How often should I save to Core Data?
When I do a change to the products, remove one or add, do I need to do anything then such as invoking some methods?
This depends on the delete rule you set in the entity in the core data model.
Upvotes: 1