Hi (topical question below).
In iOS 5, there is an introduction to the CoreData contexts of the parent-child managed entity.
I have a standard NSFetchedResultsController and UITableVeiwController that work together to get the main list from the store. The managed object context processed by the final result is a child context with a parent context:
// AppDelegate.m - (NSManagedObjectContext *)managedObjectContext { if (__managedObjectContext != nil) { return __managedObjectContext; } __managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; // primary managed object context has NSPrivateQueueConcurrencyType [__managedObjectContext setParentContext:[self primaryObjectContext]]; return __managedObjectContext; }
The table view controller is a modal view controller for adding a new record, but it uses a separate managed object context (this context is another child of the parent context). This context is stored in the delegate callback in the table view controller:
- (void)addGame { // New child context [self setBuildManagedObectContext:[[NSManagedObjectContext alloc] init]]; [[self buildManagedObectContext] setParentContext:[[[self team] managedObjectContext] parentContext]]; Team *buildTeam = (Team *)[[self buildManagedObectContext] objectWithID:[[self team] objectID]]; Game *buildGame = [NSEntityDescription insertNewObjectForEntityForName:@"Game" inManagedObjectContext:[self buildManagedObectContext]]; [buildGame setTeam:buildTeam]; BuildViewController *buildVC = [[BuildViewController alloc] initWithGame:buildGame delegate:self]; UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:buildVC]; [[self navigationController] presentViewController:navCon animated:YES completion:nil]; }
Question:
As I understand it, with parent-child contexts, the parent context received a persistence notification from its child, and then notified all its children. Therefore, in my example, the assembly context must initiate the parent context to inform the recipient of the results in order to merge the changes.
This does not happen for me, records are created successfully, but the recipient of the results does not collect them. I know that this was the case that you needed to implement your merge from a save notification (as shown in CoreDataBooks ). But I thought that the context of the child-parent solved this problem. I tried to save the child and then the parent, but it did not seem to change the situation. Can someone explain this to me please? (Note: these are not contexts for single / background threads)
Thank you very much
objective-c ios5 core-data
Cameron Mar 20 2018-12-12T00: 00Z
source share