Note that there are some explanatory texts on larger screens.

plurals
  1. POParent/Child NSManagedObjectContext not working
    primarykey
    data
    text
    <p>I'm having some trouble with Parent Child NSManagedObjectContext. The issue is that I want to use a child NSManagedObjectContext in my EventsPlanner class to create a random event. If you notice it works if you save directly to the main NSManagedObjectContext, but I want to use the child and update to the parent.</p> <p>If you see pressing the '+' button adds a new event but it looks empty.</p> <p>I'm added the example project --> <a href="https://dl.dropbox.com/u/63377498/ParentChildExperiment.zip" rel="nofollow">https://dl.dropbox.com/u/63377498/ParentChildExperiment.zip</a></p> <p><strong>Creating the child NSManagedObjectContext:</strong></p> <pre><code>- (NSManagedObjectContext *)managedObjectContext { if (_managedObjectContext != nil) { return _managedObjectContext; } AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; _managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; [_managedObjectContext setUndoManager:nil]; [_managedObjectContext setParentContext:appDelegate.managedObjectContext]; return _managedObjectContext; } </code></pre> <p><strong>Saving:</strong></p> <pre><code>Event *event = [[Event alloc] initWithEntity:self.eventEntity insertIntoManagedObjectContext:nil]; event.title = ...; event.location = ...; event.timeStamp = ...; [self.managedObjectContext insertObject:event]; [self.managedObjectContext performBlock:^{ NSError *childError = nil; if ([self.managedObjectContext save:&amp;childError]) { [self.managedObjectContext.parentContext performBlock:^{ NSError *parentError = nil; if (![self.managedObjectContext.parentContext save:&amp;parentError]) { NSLog(@"parent error: %@", [parentError description]); abort(); } }]; } else { NSLog(@"child error: %@", [childError description]); abort(); }}]; </code></pre> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload