On May 6, 2009, at 10:27 PM, Graham Cox wrote:


This happens often enough that I need a real plan. I typically have parent objects with child objects that have attributes bound to different things in a GUI or possibly even unbound and simply modified by something else. The parent object needs to perform some type of action whenever one of the (possibly) many attributes of the child object changes, such as update a file containing the data the child represents.

I'm looking for a strategy to handle watching those changes. So far I've used a few odd solutions which generally stem from overriding setValue:forKey: (or each accessor explicitly depending on the situation) in the child. I've used that to trigger an single key (isModified) which the parent watches, post a notification, call a delegate method, and probably some others. None of which I like.


Suggestions?


KVO?

Ok, maybe I should have been more explicit.

If the child object has 100 properties and a hierarchy of its own, there's no way I'm going to register the parent as an observer for each property explicitly. Barf. Which is why I said one method was to override setValue:forKey: in the child to trigger a single observable key (isModified). But I still don't like the solution much.


The parent gets to decide which attributes it's interested in, and registers itself as a KVO observer for those attributes.

The parent is always interested in *any* change to the child.


--
Seth Willits



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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

This email sent to arch...@mail-archive.com

Reply via email to