CoreData - NSManagedObjectContext notifications - Save vs DidChange ?
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