Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [CORE DATA] multithreading




On 28 févr. 06, at 17:37, Bill Bumgarner wrote:

On Feb 28, 2006, at 5:55 AM, Aurélien Hugelé wrote:
Some answers from myself

But i have some problem to understand if I have to synchronize both MOC manually or not and how? i mean, should i insert in the main thread moc (using [moc1 insertObject:[moc1 objectWithID:objectId]]) the objects i inserted in the threaded moc (ie moc2, using insertNewObjectForEntityForName:inManagedObjectContext:) ? from what i have read on this list, i have to synchronize mocs, nothing is done for me.
From my test, to make the main thread array controller aware of the new objects, i have to use insertObject: on the moc1.

reinserting an object in another context is an error, at the next save: of the context, you'll get an error, the object is already inserted blah blah blah.


So how can i make my array controllers aware of the newly inserted objects ?

NSManagedObject implements:

- (NSManagedObjectID *)objectID;

NSManagedObjectContext implements:

- (NSManagedObject *)objectWithID:(NSManagedObjectID *) objectID; // returns the object for the specified ID (the object does not already need to be registered in the context, it might be fetched or returned as a fault) - the object is assumed to exist as described by the ID

Use the first to grab the object ID from your thread, use the second to make the main event loop's MOC aware of the object.

Oh, and be very careful when working with threads. They can easily be woven into a nice hangman's rope....

b.bum


Thanks for the answer, i have already use [moc1 objectWithID:], in my code above. I already succeeded to get the background-thread-inserted- object "realized" in the main thread, but what is *not* working, is the update of the array controllers:
Since the object has not been inserted in the main thread (but only "realized" via objectWithID:), the array controllers are not informed of the insertion, and thus the tableview is not displaying the new object.


i've reverse engineered what happen when an object inserted into a context, and how array controllers (_NSManagedProxy) are informed via @"_NSObjectsChangedInManagingContextPrivateNotification" notification... but this of course occurs when an object is inserted in the context *observed by the arraycontroller*.
My object is inserted in the *subthread context* (and saved in this thread), not the one observed by the array controller and thus the array controllers in the main thread are not informed of the insertion...


any idea ?



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >[CORE DATA] multithreading (From: Aurélien Hugelé <email@hidden>)
 >Re: [CORE DATA] multithreading (From: Aurélien Hugelé <email@hidden>)
 >Re: [CORE DATA] multithreading (From: Bill Bumgarner <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.