• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Core Data Concurrency Issues
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Core Data Concurrency Issues


  • Subject: Core Data Concurrency Issues
  • From: Jeff Kelley <email@hidden>
  • Date: Thu, 04 Aug 2011 17:29:39 -0400

I’m having some issues with concurrency with Core Data. I create an object
that has a to-many relationship with another object (which in turn has a
to-one reciprocal relationship with the first object), then dispatch_async
onto a private queue. In that queue, I use a separate managed object
context, which I’ve created earlier and only use within that queue. Here’s a
snippet:

ParentObject *parent = [NSEntityDescription
insertNewObjectForEntityName:@"ParentObject"]
inContext:[self moc]];

NSManagedObjectID *objectID = [parent objectID];

dispatch_async(dedicatedQueue, ^{
// Note: childContext is an NSManagedObjectContext that has been created
earlier and is only used within this queue.
 ParentObject *parent = [childContext objectWithID:userID];

for (NSDictionary *jsonDict in allChildDicts) {
 ChildObject *child = [NSEntityDescription
insertNewObjectForEntityName:@"ChildObject"]
inContext:childContext];
[parent addChildObject:child];
 }
});


If I try to save the context within the dedicated queue, I get validation
errors on the child objects with the text “Dangling reference to an invalid
object.”

It appears to work correctly if I create the parent object within the
dedicated child queue. So, what is the proper way to create these objects on
the main queue and then update them in the background? Thanks in advance.

Jeff Kelley
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Core Data Concurrency Issues
      • From: Heath Borders <email@hidden>
  • Prev by Date: Re: Menu Item Key Equivalent
  • Next by Date: Re: Correct way to use contextInfo with ARC
  • Previous by thread: [SOLVED] Re: CoreData "I/O error for database: no such table"
  • Next by thread: Re: Core Data Concurrency Issues
  • Index(es):
    • Date
    • Thread