Re: [CoreData] Background Insertion
Re: [CoreData] Background Insertion
- Subject: Re: [CoreData] Background Insertion
- From: "Marcus S. Zarra" <email@hidden>
- Date: Tue, 5 Jun 2007 10:08:57 -0600
The order should be as follows:
1. Insert objects on background thread
2. Hold a reference to these objects
3. Save objects on background thread
4. Build an array list of objectIDs on background thread
5. Send array list of objectIDs to main thread
6. Update on main thread.
If you retrieve the objectIDs from the managed objects after they
have been saved then they should have their permanent unique ids.
Marcus S. Zarra
Zarra Studios LLC
Simply Elegant Software for OS X
www.zarrastudios.com
On Jun 5, 2007, at 9:59 AM, Andrew Kimpton wrote:
On Jun 5, 2007, at 11:27 AM, Marcus S. Zarra wrote:
Andrew,
I do updates on a background thread also. When I am done on the
background thread I then make a call to the main thread and I pass
it the objectID for each object that was touched in the background
thread. Then on the main thread, I loop through these objectIDs
and call -refreshObject:mergeChanges: on each object. This lets
the main thread know that the object has changed and handles
updates from the main thread properly.
I am not sure how viable this would be in your case but it is a
solution that does work.
This would be a fine solution for me - however my problem is that
objectRegisteredForID returns nil when called against the managed
object context in the main thread for an object ID that was just
inserted into the context of the background thread. For other
scenarios where the background thread has caused an update to the
object then the objectRegisteredForID call returns a valid pointer.
It's only the newly inserted objects for which I get nil.
In your app are you also inserting objects in the background
thread ? Or only causing updates to already existing objects ? If
you are inserting objects do you also send a save message to the
background threads context during the processing of the background
thread ? Or do you defer the save to the main thread for some later
date ? Right now I save in the background thread too - and I'm
wondering if that causes a problem (I do lock the store coordinator).
Andrew 8-)
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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