On May 19, 2009, at 14:18, Stuart Malin wrote:
As my understanding of Bindings is that they implement using KVO and KVC, then is it safe to assume that if an object has a bindable property, then that property should be observable with KVO, yes?
No. The name of the binding is *not* the same as the name of any property of the bound object. For example, most controls have a "value" binding, but controls don't have a "value" property.
The assumption underlying your assumption, that there is some sort of direct correlation between a binding and an underlying property, is also false. Typically, bindings will be implemented so as to use one or more properties of the bound object, but that's not a requirement (except perhaps in a looser conceptual sense).
My specific concern is with NSSegmentedControl, which has a bindable property "selectedIndex". I am trying to add an observer for this property (using -addObserver: on an instance). Alas, I am not getting an observer event (i.e, invocation of my - observerForKeyPath:... method) when I change the segmented control in the U/I. So, either I have done something incorrectly in setting up the observer, or this is not an observable property.
Pendantically, there's no such thing as a "bindable property". NSSegmentedControl has a binding named "selectedIndex" and a property named "selectedSegment" which (presumably) the binding uses. So, you should observe the "selectedSegment" property, not the (non-existent) "selectedIndex" property.
Incidentally, the relationship between the binding and the property is an implementation detail. It's not impossible that the "selectedIndex" binding might use a privately-known property, and that "selectedSegment" is derived from that private property in a non-KVO- compliant way. It's not impossible, therefore, that observing "selectedSegment" doesn't work, regardless of bindings.
Finally, it usually indicates a design flaw if you're trying to observe a property of a user interface object. It's almost always better to observe the value that the UI object is bound to. (There are valid exceptions, though.)
_______________________________________________ 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