• 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
CoreData: NSManagedContext not updating NSArrayController in UI
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CoreData: NSManagedContext not updating NSArrayController in UI


  • Subject: CoreData: NSManagedContext not updating NSArrayController in UI
  • From: Marc Monguio <email@hidden>
  • Date: Mon, 21 Nov 2005 00:59:58 -0800

This is the picture of my problem I'm facing:

I'm trying to update the main moc (NsManagedObjectcontext *) with the new values inserted from another moc in another thread. I want an NSArrayController to show the moc's new registered values in the interface
(Note: both mocs share the same nsstorecoordinator)


What I do is catch the "NSManagedObjectContextDidSaveNotification" notification sent by the second thread when doing a "moc:save". Then "performSelectorOnMainThread" that calls a method where I register the new inserted values:

- (void)handleMocWasSavedNotification:(NSNotification *)aNotification
{
[self performSelectorOnMainThread:@selector (updateManagedObjectContext:) withObject:aNotification waitUntilDone:NO];
}


- (void)updateManagedObjectContext:(NSNotification *)aNotification;
{
NSManagedObject *insertedObject;
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
staleObject = [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];
}
}


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];
}



But, is "correct" way of doing it? What I'm doing wrong in the former solution?

Thanks in advance for your answers.
regards,
Marc

_______________________________________________
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


  • Follow-Ups:
    • Re: CoreData: NSManagedContext not updating NSArrayController in UI
      • From: mmalcolm crawford <email@hidden>
    • Re: CoreData: NSManagedContext not updating NSArrayController in UI
      • From: Jim Correia <email@hidden>
  • Prev by Date: Re: How can i determine the mac pixel ratio?
  • Next by Date: Re: How can i determine the mac pixel ratio?
  • Previous by thread: Re: NSTextView completion fun
  • Next by thread: Re: CoreData: NSManagedContext not updating NSArrayController in UI
  • Index(es):
    • Date
    • Thread