Re: Threads and Core Data, bindings results in view corruption
Re: Threads and Core Data, bindings results in view corruption
- Subject: Re: Threads and Core Data, bindings results in view corruption
- From: Jeff LaMarche <email@hidden>
- Date: Sat, 29 Mar 2008 23:48:40 -0400
Dave:
Are you using separate managed object contexts for each thread?
According to the documentation here:
http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdMultiThreading.html
That's the way to do it - pass managed object IDs between threads, not
managed objects, and when you're done, you can call
refreshObject:mergeChanges: on the main thread's context with the
objects that were changed, then call processPendingChanges on it.
With regards to getting the tree controller to update, though, I've
had the same problem - I can't get the tree controller to recognize
the changes made in the other thread, even though those changes are
saved successfully and I tell the main thread's context about them.
They do show up the next time I launch the app. I'm actually in the
process of rewriting my app to avoid threads in a few places because
of this problem (and because it's the right thing to do based on Jens'
advice given to somebody else earlier today). If you do figure out the
tree controller issue, though, I'd love to know how you got it to
work. I've posted the question twice now to this list - once about two
years ago, and another time today with no luck. :(
Take care,
Jeff
On Mar 29, 2008, at 11:30 PM, David wrote:
I would think this is the normal typical case, but can't figure it
out.
The UI should run on one thread, another thread should be used for
time
consuming updates/generation of an object tree maintained using Core
Data. I
have a NSOutlineView (via NSTreeController subclass) which displays
the
object tree from Core data.
I can not figure out how to make this thread safe. I periodically
get random
data showing up in the outline view while the core data object tree
is being
updated.
I've tried locking the managedObjectContext when I make additions or
changes
to the object tree, but I still get erroneous data showing up in the
view.
I don't understand how NSTreeController and bindings are interacting
with
Core data to extract the data while I'm populating it.
Any suggestions greatly appreciated.
I've been reading and rereading the Core Data programming guide and
Threading programming guide to no avail.
The Core data programming guide says its best to maintain a separate
managedObjectContext per thread. But this appears to require the
data to be
written to persistent store to make it work (file). That not
reasonable in
my case where I'm adding many objects to an object tree. It takes a
significant amount to time to write it out, negating the benefit of
trying
to make the UI seem responsive.
I'm running Leopard.
_______________________________________________
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
_______________________________________________
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