Skip navigation.
 
mlRe: NSTableView, NSArrayController, NSManagedObjectContext
FROM : Ture Pålsson
DATE : Tue Jan 01 18:38:07 2008

On Jan 1, 2008 6:17 PM, mmalc crawford <<email_removed>> wrote:
>
> On Jan 1, 2008, at 4:25 AM, Ture Pålsson wrote:
>
> > Then I have another NSManagedObjectContext, with the same core data
> > stack beneath it. When I add objects to this MOC (on another thread),
> > the do _not_ pop up in the NSTableView until I restart my application.
> > What exactly do I need to do get these objects into the MOC bound to
> > the table view, so that the table view updates correctly?
> >
> <http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdChangeManagement.html#//apple_ref/doc/uid/TP30001201-DontLinkElementID_18


Thank you, I have read that about a gazillion times but I am obviously
managing to overlook some important bit of it...

Here's what I do:

In the thread that adds the objects, I do [moc save: &saveError] every
now and then.

I subscribe to NSManagedObjectContextDidSaveNotification. In the
notification handler, I extract the object ID:s of the inserted
objects and pass them to a method on the main thread (using
performSelectorOnMainThread). On the main thread, I loop over the
objectID:s and... well, what *should* I be doing here? I tried just
accessing the objects with [moc objectWithID:]. No luck. I tried
calling [moc refreshObject: mergeChanges:] for the objects I got by
objectByID. No luck. I tried executing fetch requests for those
objects. No luck.