• 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 - NSManagedObjectContext notifications - Save vs DidChange ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CoreData - NSManagedObjectContext notifications - Save vs DidChange ?


  • Subject: CoreData - NSManagedObjectContext notifications - Save vs DidChange ?
  • From: Simon Liu <email@hidden>
  • Date: Wed, 5 Oct 2005 21:38:43 +0100

Hi,

I have a background thread with a private NSManagedObjectContext, which is
updating an object's mutable set (1..n relationship). The updates are
visible in a tableview, which is wired to an arraycontroller in the main
application's shared context.

This works okay if during my background thread's computation, I invoke
-save: on the private context. I have a notification handler to handle
NSManagedObjectContextDidSaveNotification. The handler is responsible for
taking the updated objects from the private context and refreshing them in
the application's shared context. So all good...

Except that if I use the same handler for
NSManagedObjectContextObjectsDidChangeNotification, I notice that the
tableview does not update. It seems as though the array controller can't
"see" the refreshing. Is there any way to make this happen, as I thought it
would be possible to do this, without having to invoke -save: which is more
expensive as it writes to the store.

I think my notification handler is fairly standard. Here are the key bits:

// Get all objectIDs, where notification object is my private context
[objects unionSet:[userInfo objectForKey:NSInsertedObjectsKey]];
[objects unionSet:[userInfo objectForKey:NSUpdatedObjectsKey]];
[objects unionSet:[userInfo objectForKey:NSDeletedObjectsKey]];

// Enumerate, and then refresh
if (staleObject = [sharedContext objectRegisteredForID:[obj objectID]]) {
[sharedContext refreshObject:staleObject mergeChanges:NO];
}
[sharedContext processPendingChanges];

Any advice appreciated. Thanks.

Regards,
--Simon
 _______________________________________________
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 - NSManagedObjectContext notifications - Save vs DidChange ?
      • From: Chris Hanson <email@hidden>
    • Re: CoreData - NSManagedObjectContext notifications - Save vs DidChange ?
      • From: Bill Cheeseman <email@hidden>
  • Prev by Date: Re: strange malloc error with NSWindow makeKeyAndOrderFront:
  • Next by Date: Custom PopUpButton problems
  • Previous by thread: NSPersistentDocument Tutorial Question
  • Next by thread: Re: CoreData - NSManagedObjectContext notifications - Save vs DidChange ?
  • Index(es):
    • Date
    • Thread