Re: Bound Property
Re: Bound Property
- Subject: Re: Bound Property
- From: Ken Thomases <email@hidden>
- Date: Fri, 20 Mar 2009 00:24:00 -0500
On Mar 19, 2009, at 11:49 PM, Richard Somers wrote:
On Mar 19, 2009, at 9:05PM, Chris Hanson wrote:
Bindings in Cocoa are not the same thing as the properties that may
be used to implement their storage. [...]
The Cocoa Bindings Reference documentation lists all built-in
bindings that are available in the frameworks. Every one of them has
an Objective-C type method name like myBinding not "My Binding".
The NSKeyValueBindingCreation Protocol Reference describes the class
method +(void)exposeBinding:(NSString *)binding where the binding
parameter is "The key path for the property to be exposed." So a
property is exposed by the binding.
The property may not correspond to an instance variable but there
will be accessors for the property. A property named "My Property"
simply can not exist in code. Spaces are not allowed in method names.
Right?
Not quite.
First, you are correct that IB displays human-friendly names for some
bindings rather than the actual binding name as would be used in
code. Why it does this is something you'll have to ask Apple. It
doesn't bother me, particularly.
However, it's true that bindings are not the same as properties. For
example, the bindings reference lists a binding on NSTextField called
"value". But there's no "value" property for NSTextField.
Also, the quote from the documentation above says the binding
parameter is a "key path", but it's not. If you try to use a path --
multiple keys separated by dots -- for a binding name you'll
eventually get an error. Perhaps not with the +exposeBinding: method,
but with some of the other bindings methods which claim that a binding
is a key path (e.g. -bind:toObject:withKeyPath:options:). I've
submitted documentation feedback about that, but no change so far.
I don't know whether it's legal or workable to use a binding whose
name contains a space. I wouldn't expect it to work. However, it's
not because there must be method names corresponding to the binding
name. There needn't be. (Even if a binding were a property, it is
not necessary for there to be methods with a corresponding name. The
property could exist solely via -valueForKey:. As an example, all the
keys in a dictionary are properties of that dictionary, but they may
contain spaces. Especially confusing for KVC, they may even include
dots, like for example @"John Q. Public".)
Regards,
Ken
_______________________________________________
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