Re: mergeChangesFromContextDidSaveNotification effects
Re: mergeChangesFromContextDidSaveNotification effects
- Subject: Re: mergeChangesFromContextDidSaveNotification effects
- From: Nathan Vander Wilt <email@hidden>
- Date: Mon, 19 Jan 2009 12:09:44 -0800
I figured this out. Core Data sends out several separate
ContextDidChange notifications in response to a single -
mergeChangesFromContextDidSaveNotification call. I had a dumb bug in
my code that resulted in me only seeing the first one.
The object where I was debugging ContextDidChange notifications (and
doing my caching) was the very one I was getting the first "refreshed"
notification for — and I was removing it as a notification observer in
its -didTurnIntoFault. So it would get turned to a fault first thing
when merging the save notification, unregister itself as a result, and
then no longer behave as intended. I moved the notification center
unregistration to -dealloc, and now I can see that my merge does
result in all the expected insertions, just with separate notifications.
Hope this can help someone else realize that Core Data doesn't
(necessarily) hate them if they come across my original post.
-natevw
On Jan 16, 2009, at 2:02 PM, Nathan Vander Wilt wrote:
My application imports into an NSManagedObjectContext created on a
background thread. As the last stage of this import, I save the
background context to the persistent store. All my UI code uses a
managed object context on the main thread, and expects to be
notified via NSManagedObjectContextObjectsDidChangeNotification to
update caches and redisplay.
So... in my background thread I catch the
NSManagedObjectContextDidSaveNotification and pass it to a method
called on the main thread to -
mergeChangesFromContextDidSaveNotification: in the main context. Now
I would expect that all the objects I inserted into the background
context would get inserted into the main context, and I would see
evidence of this in the ObjectsDidChange notification. While the
save notification has @"inserted" and @"updated" sets with the
expected objects, the change notification only contains the updated
object in its @"refreshed" set, and no inserted objects.
Is this what I should expect? Is there a better way I can trigger
the ObjectsDidChange notification on my main context after another
context updates the persistent store? Or, taking things a step back,
what's the best way to keep Core Data fetch request results up-to-
date?
thanks,
-natevw
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden