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

Re: [CoreData] Background Insertion


  • Subject: Re: [CoreData] Background Insertion
  • From: Dave Fernandes <email@hidden>
  • Date: Mon, 4 Jun 2007 19:09:18 -0400

If your main thread does not have unsaved changes, you can send a reset message to the MOC, as in,
[moc reset];


This will cause it to go back to the persistent store. If you have unsaved changes, however, then I don't know what to do.

On Jun 4, 2007, at 6:23 PM, Andrew Kimpton wrote:

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:
40utoronto.ca


This email sent to email@hidden

_______________________________________________

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: Andrew Kimpton <email@hidden>
    • Re: [CoreData] Background Insertion
      • From: Andrew Kimpton <email@hidden>
References: 
 >[CoreData] Background Insertion (From: Andrew Kimpton <email@hidden>)

  • Prev by Date: [CoreData] Background Insertion
  • Next by Date: NSView and Cursor rects
  • Previous by thread: [CoreData] Background Insertion
  • Next by thread: Re: [CoreData] Background Insertion
  • Index(es):
    • Date
    • Thread