• 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
[CoreData] Background Insertion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[CoreData] Background Insertion


  • Subject: [CoreData] Background Insertion
  • From: Andrew Kimpton <email@hidden>
  • Date: Mon, 4 Jun 2007 18:23:57 -0400

My application needs to insert a several hundred entities into a CoreData store as a result of parsing an XML file. In order to not 'block' the main UI thread I create a second thread and in that thread create a second NSManagedObjectContext (for the same NSPersistentStoreCoordinator as the main thread). My parsing and insertions seem to go fine and I can save the managedObjectContext at the end of parsing without error.

However the NSArrayController(s) and other bound items in the UI don't seem to reflect the newly inserted items.

If I handle the NSManagedObjectContextDidSaveNotification in the worker thread and use it to create an array of object id's for the newly inserted items when I enumerate that array in my main thread (and with the main threads ManagedObjectContext) using objectRegisteredForID the returned object for each ID is always nil. If I run my import a second time so that I'm updating rather than inserting a lot of objects the same code gives me valid object pointers.

Am I missing something in how to co-ordinate the two managedObjectContexts so that all the items inserted in one appear in the other ? I've tried settings things like the merge policy (store trumps objects) and also the setRetainsObjects flag on the managedObjectContexts to no avail.

I know that my data has 'hit the disk' since if I quit and relaunch the app then the array controllers and bound items all have the appropriate data and displays. It's only the 'initial import' into an empty persistent store and managedObjectContext that seems troublesome.

Thanks for any help

Andrew 8-)

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: [CoreData] Background Insertion
      • From: Dave Hayden <email@hidden>
    • Re: [CoreData] Background Insertion
      • From: Dave Fernandes <email@hidden>
  • Prev by Date: Re: NSTableView select a single cell
  • Next by Date: Re: [CoreData] Background Insertion
  • Previous by thread: Re: NSTextField value changes after tab-through
  • Next by thread: Re: [CoreData] Background Insertion
  • Index(es):
    • Date
    • Thread