Re: watch changes to any properties on an object
Re: watch changes to any properties on an object
- Subject: Re: watch changes to any properties on an object
- From: Alexander Cohen <email@hidden>
- Date: Thu, 3 Sep 2009 16:08:53 -0400
Overriding willChangeValueForKey: was one of the first things i tried
before posting and I noticed it was not being called, i thought it was
weird but nothing more. Good to know that overriding it was
deprecated. Thx for the info on how CoreData manages it's saves. I was
hoping to not have to create setters for all the values that can
change my dirty flag but i guess ill have to. I guess what i'm looking
for is a method like setSelector:forChangesOnProperties:.
thx
AC
On Sep 3, 2009, at 3:30 PM, Ben Trumbull wrote:
Well, @dynamic doesn't have anything to do with KVO. It's just
storage and accessors for properties. Core Data knows when non-
dynamic modeled properties change too. It sets a dirty flag, just
as you would have to. Most of that happens in -
willChangeValueForKey:. Unfortunately, overriding that method was
deprecated in 10.5. KVO no longer guarantees overrides will be
called.
In terms of knowing what to save, Core Data only tracks that at an
object level, and uses snapshot deltas to compute the changed
property set at the end.
Some people invert the observing relationship to work around this.
You can add code in your setters to set a dirty flag, or within your
setters manually call a notify method on another object. If you
have fewer objects, you could just use NSNotifications.
Almost certainly worth filing an enhancement request at bugreport.apple.com
- Ben
Ok, thats what i thought. But just for implementation ideas, how does
CoreData know when one of it's @dynamic properties is changed? It
must
set some sort of flag somewhere in order to know what to write out
when it needs to save. How does it handle that?
thx
AC
On Sep 3, 2009, at 12:27 PM, Jens Alfke wrote:
On Sep 3, 2009, at 8:24 AM, Alexander Cohen wrote:
I have a base object that needs to know when any of it's properties
or subclasses properties have changed and set a dirty flag on
itself. Is there a way to do this?
No, not in general. Key-value observing requires knowing the exact
property name(s) in advance. You'll need to set the 'dirty' flag
manually.
˜Jens
_______________________________________________
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
_______________________________________________
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