Re: Core-Data Multithreading question about save
Re: Core-Data Multithreading question about save
- Subject: Re: Core-Data Multithreading question about save
- From: Ben Trumbull <email@hidden>
- Date: Thu, 22 May 2008 14:07:59 -0700
At 3:55 AM -0700 5/22/08, email@hidden wrote:
Il giorno 22/mag/08, alle ore 01:00, Hamish Allan ha scritto:
Do you really need to do this after every object inserted? Could you
do it in bulk?
Not necessarily.
I've tried to do this sequence:
- my second thread add objects into second context until the end
saving each objectID in an array
- after all insertions was finished I call -save: on second context
then I try to take the object from the main context using the objectID
saved. However the object seems not updated (all attributes was empty)
and I've noticed that saved objectID is temporany. I've also tried to
save both second/first managedobject before doing these actions but
the id still temporany.
What's I'm wrong? The ID still temporany until I save the second
managed object but If I can do it I can also make my relationship, the
overhead it's the same.
The doc says I can pass objects between contexts by the relative ID
(but if the ID is temp what should I need to pass...?).
You're grabbing the objectID from the inserted object before it's
saved. You need to get the permanent ID from the object after it's
been saved, or you've used -obtainPermanentIDForObjects:error: (which
also does I/O, and should be used on a batch of objects)
The list archives also have these, which you should read:
<http://lists.apple.com/archives/cocoa-dev/2007/Mar/msg00739.html>
<<http://lists.apple.com/archives/cocoa-dev/2007/May/msg00222.html>http://lists.apple.com/archives/cocoa-dev/2007/May/msg00222.html>
<<http://lists.apple.com/archives/cocoa-dev/2008/Jan/msg01889.html>http://lists.apple.com/archives/cocoa-dev/2008/Jan/msg01889.html>
<http://lists.apple.com/archives/cocoa-dev/2008/Mar/msg02554.html>
--
-Ben
_______________________________________________
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