• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CoreData: NSManagedContext not updating NSArrayController in UI
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CoreData: NSManagedContext not updating NSArrayController in UI


  • Subject: Re: CoreData: NSManagedContext not updating NSArrayController in UI
  • From: Marc Monguio <email@hidden>
  • Date: Mon, 21 Nov 2005 11:34:09 -0800

If you have simply inserted objects in another moc, then they aren't stale in this moc, since they've never been registered. Your loop should be using objectRegisteredForID: and only refreshing those (so as to not pull in objects that no one wasn't already paying attention to.

- (void)updateManagedObjectContext:(NSNotification *)aNotification;
{
NSManagedObject *insertedObject;
NSManagedObject *dontCareObject;
NSSet *registeredObjects = [moc registeredObjects];
NSSet *insertedObjects = [[aNotification userInfo] objectForKey:NSInsertedObjectsKey];
while ((insertedObject = [enumerator nextObject]) != nil) {
//this should register the insertedObject from the other thread to the main moc
//doesn't it?
dontCareObject = [moc objectWithID:[insertedObject objectID]];
//to be sure I refresh it, it doesn't work either...
[moc refreshObject:staleObject mergeChanges:NO];
//to be sure I save, it doesn't work either...
[moc save:&error];
}
}


I didn't meant to put that name to the staleObject (now 'dontCareObject') variable, in fact I'm not interested in that variable at all. What I want is to register the objects inserted in the other moc into the main one, according to the docs the "objectWithID:" method should register? "DOCS: If the object is not registered in the context, it may be fetched or returned as a fault".
If I use objectRegisteredForID: for all the objects that I have inserted in the other moc it doesn't work because I get returned nils (the objects doesn't exist in that context) nor they are not registered.
What I really need is a way of registering objects to a moc that already reside in the nspersistentcoordinator. The nsarraycontroller is binded to the same moc so it should update automatically.




So what I'm doing is populate the main moc that is also used in the NSArrayController. But the NSArrayController doesn't show the new inserted values in the UI unless I ask for a fetch:
- (void)updateManagedObjectContext:(NSNotification *)aNotification;
{
[myArrayController fetch:self];
}

As far as I know, this is the only way to get your controller to react to insertions/deletions in another moc.

It's good to know, but what I really want it to update the moc with the new registered objects from the other moc. I'm afraid that with this workaround it wont be as fast as doing it with the former approach (which still doesn't work).
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
References: 
 >CoreData: NSManagedContext not updating NSArrayController in UI (From: Marc Monguio <email@hidden>)
 >Re: CoreData: NSManagedContext not updating NSArrayController in UI (From: Jim Correia <email@hidden>)

  • Prev by Date: NSURLConnection not reentrant?
  • Next by Date: Re: URL loading system not threadsafe?
  • Previous by thread: Re: CoreData: NSManagedContext not updating NSArrayController in UI
  • Next by thread: Re: CoreData: NSManagedContext not updating NSArrayController in UI
  • Index(es):
    • Date
    • Thread