Re: How to know whether property in Cocoa class is KVO-compliant?

2010-01-11 Thread Scott Anguish

On Jan 10, 2010, at 11:18 PM, Dave Fernandes wrote:

 Look for Cocoa Bindings Guide in the docs. It would be nice if it were 
 cross-referenced in every class description.

Please file a bug about that.

Class methods that are KVO compatible are stated as such in the reference. They 
aren’t pervasive at this point, but many more became KVO compatible in Snow 
Leopard. 

I think it’s safe to expect more methods will become KVO compliant in the 
future. And the reference will be updated to reflect those that are.


___

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


Re: How to know whether property in Cocoa class is KVO-compliant?

2010-01-11 Thread Quincey Morris
On Jan 10, 2010, at 19:58, Jerry Krinock wrote:

 After studying some about bindings during the last week, I decided that, just 
 for fun, I would bind an NSSegmentedControl to its window controller using a 
 binding instead of target/action.  I thought that selectedSegment might be a 
 KVO-compliant property of NSSegmentedControl because it has a 
 -selectedSegment and -setSelectedSegment: method.
 
 So I exposed a binding named @foo in my window controller's +initialize, in 
 -awakeFromNib I added this:
 
  [windowController bind:@foo
toObject:segmentedControl
 withKeyPath:@selectedSegment
options:0] ;

Adding on to mmalc's response, to make this explicit:

You *didn't* bind an NSSegmentedControl to its window controller, you 
actually bound a window controller['s foo binding] to [the selectedSegment 
property of] a NSSegmentedControl.

IIRC the bindings documentation isn't clear which direction is bound to 
refers to and/or it gives the impression that a binding is symmetric (which it 
may effectively be at the level of notifications, but it isn't at the level of 
establishing bindings between objects).


___

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


How to know whether property in Cocoa class is KVO-compliant?

2010-01-10 Thread Jerry Krinock
After studying some about bindings during the last week, I decided that, just 
for fun, I would bind an NSSegmentedControl to its window controller using a 
binding instead of target/action.  I thought that selectedSegment might be a 
KVO-compliant property of NSSegmentedControl because it has a -selectedSegment 
and -setSelectedSegment: method.

So I exposed a binding named @foo in my window controller's +initialize, in 
-awakeFromNib I added this:

  [windowController bind:@foo
toObject:segmentedControl
 withKeyPath:@selectedSegment
 options:0] ;

and finally in a windowWillClose cleanup method I added an unbind:.

The above code compiled and ran without any bitchin' from out of the console, 
and at any time in the program if I send -infoForBinding:@foo to 
windowController, I log the expected result:

bindingInfo = {
NSObservedKeyPath = selectedSegment;
NSObservedObject = NSSegmentedControl: 0x1b879c90;
NSOptions = {
NSMultipleValuesPlaceholder = null;
NSNoSelectionPlaceholder = null;
NSNotApplicablePlaceholder = null;
NSNullPlaceholder = null;
NSRaisesForNotApplicableKeys = 1;
NSValueTransformer = null;
NSValueTransformerName = null;
};
}

But it just didn't work.  Flipping that segmented control in the user 
interface never caused my window controller's -setFoo: to run.

Did I do anything wrong?

If not, I conclude that NSSegmentedControl's is not KVO-compliant for property 
'selectedSegment'.  That is, the class implementation probably changes the view 
without invoking the setter.

I changed to target/action and it works fine.

So how does one know whether a property in Cocoa class is KVO-compliant?  I 
can't find an answer in the Key-Value Observing Programming Guide.  I thought 
maybe there's a little point system:

1.  Property has a setter and getter; i.e. -bar and -setBar:.  Add 2 points.
2.  I remember seeing, every now and then, in newer API documentation, a 
notation that this property is observeable, or something like that.  Add 8 
points.
3.  Add 1 point for each Mac OS X dot release that the class first appeared in. 
 0 points for 10.0, 1 point for 10.1, etc.
4.  If the class is a view layer class, subtract 2 points.  Most people don't 
usually bind to view classes.
5.  Test it and see if it works.  Add 5 points.  What is the possibility that 
it could stop working in a future Mac OS X release?


___

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


Re: How to know whether property in Cocoa class is KVO-compliant?

2010-01-10 Thread Dave Fernandes
Look for Cocoa Bindings Guide in the docs. It would be nice if it were 
cross-referenced in every class description. SelectedIndex should work for a 
segmented control. Haven't tried it myself though.

Cheers,
Dave

On 2010-01-10, at 10:58 PM, Jerry Krinock wrote:

 After studying some about bindings during the last week, I decided that, just 
 for fun, I would bind an NSSegmentedControl to its window controller using a 
 binding instead of target/action.  I thought that selectedSegment might be a 
 KVO-compliant property of NSSegmentedControl because it has a 
 -selectedSegment and -setSelectedSegment: method.
 
 So I exposed a binding named @foo in my window controller's +initialize, in 
 -awakeFromNib I added this:
 
  [windowController bind:@foo
toObject:segmentedControl
 withKeyPath:@selectedSegment
options:0] ;
 
 and finally in a windowWillClose cleanup method I added an unbind:.
 
 The above code compiled and ran without any bitchin' from out of the console, 
 and at any time in the program if I send -infoForBinding:@foo to 
 windowController, I log the expected result:
 
 bindingInfo = {
NSObservedKeyPath = selectedSegment;
NSObservedObject = NSSegmentedControl: 0x1b879c90;
NSOptions = {
NSMultipleValuesPlaceholder = null;
NSNoSelectionPlaceholder = null;
NSNotApplicablePlaceholder = null;
NSNullPlaceholder = null;
NSRaisesForNotApplicableKeys = 1;
NSValueTransformer = null;
NSValueTransformerName = null;
};
 }
 
 But it just didn't work.  Flipping that segmented control in the user 
 interface never caused my window controller's -setFoo: to run.
 
 Did I do anything wrong?
 
 If not, I conclude that NSSegmentedControl's is not KVO-compliant for 
 property 'selectedSegment'.  That is, the class implementation probably 
 changes the view without invoking the setter.
 
 I changed to target/action and it works fine.
 
 So how does one know whether a property in Cocoa class is KVO-compliant?  I 
 can't find an answer in the Key-Value Observing Programming Guide.  I thought 
 maybe there's a little point system:
 
 1.  Property has a setter and getter; i.e. -bar and -setBar:.  Add 2 points.
 2.  I remember seeing, every now and then, in newer API documentation, a 
 notation that this property is observeable, or something like that.  Add 8 
 points.
 3.  Add 1 point for each Mac OS X dot release that the class first appeared 
 in.  0 points for 10.0, 1 point for 10.1, etc.
 4.  If the class is a view layer class, subtract 2 points.  Most people 
 don't usually bind to view classes.
 5.  Test it and see if it works.  Add 5 points.  What is the possibility that 
 it could stop working in a future Mac OS X release?
 
 
 ___
 
 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/dave.fernandes%40utoronto.ca
 
 This email sent to dave.fernan...@utoronto.ca

___

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


Re: How to know whether property in Cocoa class is KVO-compliant?

2010-01-10 Thread mmalc Crawford

On Jan 10, 2010, at 8:18 pm, Dave Fernandes wrote:

 Look for Cocoa Bindings Guide in the docs. It would be nice if it were 
 cross-referenced in every class description. SelectedIndex should work for a 
 segmented control. Haven't tried it myself though.
 
No; the Cocoa Bindings Reference doesn't catalogue KVO compliance, it lists 
bindings.
In general, controller objects observe model objects, and views observe 
controllers and models -- you typically don't bind to views. Thus you shouldn't 
generally expect views' properties to be observable.

mmalc

___

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