Re: Observing Managed Object Changes. Was: Strange ... behavior
Re: Observing Managed Object Changes. Was: Strange ... behavior
- Subject: Re: Observing Managed Object Changes. Was: Strange ... behavior
- From: Dave Fernandes <email@hidden>
- Date: Wed, 25 Feb 2009 19:39:31 -0500
On Feb 25, 2009, at 8:31 AM, Jerry Krinock wrote:
So, it looks like, for observing changes to the properties of
managed objects ---
* Using NSManagedObjectContextObjectsDidChangeNotification is no good
since it doesn't give you specific information on the current
change
which actually caused the notification.
* Using KVO is no good because observers must be removed before an
object becomes a fault, and there is no mechanism to find out
when the object un-becomes a fault, which you need to restore
your observers.
So, my conclusion is that writing Custom Setters for any properties
that need to be observed and posting a notification (coalesced,
for efficiency) within the custom setter is the only viable technique.
Does anyone have any better ideas?
Jerry
Well, as I mentioned I have stuck with KVO. I don't see why you need
to remove observers when turning into a fault. You only need to
remove observers before the object disappears. I have created my own
NSManagedObject subclass as you have, and I have a
-removeSelfFromObserveredObjects method in that subclass that I call
before deallocating the MOC. (Fetch all objects from MOC and call
this method, if it exists.) ...it's not pretty, but it works.
Note that a fetch will not return deleted objects that might still be
on the undo stack, so I also call removeSelfFromObserveredObjects
from the managed object's dealloc method. (You will have to check
that you do not call removeSelfFromObserveredObjects twice.) As I
said, it's not pretty, but it works.
If anyone has a better way, I'd love to hear it!
Dave
_______________________________________________
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