On Aug 21, 2012, at 3:53 AM, Andreas Grosam wrote:

> So, in order to implement KVO, I would need to track changes of the ivar 
> _state, and invoke 
> -willChangeValueForKey:, and 
> -didChangeValueForKey: 
> appropriately.
> 
> But, how exactly can I accomplish this with the given code above?

You can call will/did around a change which doesn't actually change the value, 
so it becomes straightforward. 


Also, especially if the number of fields grows, you may want to have a KVC 
"state" property (not necessarily public), and use 

+ (NSSet *)keyPathsForValuesAffectingFoo / Bar; { return [NSSet 
setWithObject:@"state"]; }

That way you only need to do will/didChangeValueForKey:@"state" and the other 
KVO methods get triggered as well, instead of having to next multiple will/dids 
for each key (foo, bar, blah, blah) around every state change.


--
Seth Willits





_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to