Re: Binding name must be same as ivar name?
Re: Binding name must be same as ivar name?
- Subject: Re: Binding name must be same as ivar name?
- From: glenn andreas <email@hidden>
- Date: Thu, 24 Feb 2005 11:39:12 -0600
On Feb 24, 2005, at 11:26 AM, Ricky Sharp wrote:
On Thursday, February 24, 2005, at 11:11AM, Sean McBride
<email@hidden> wrote:
On 2005-02-24 10:52, Ricky Sharp said:
Sorry for not being clear, but the issue at hand is really what the
documentation [1] states (soon after Figure 6):
"Note that the binding name need not necessarily correspond to the
name
of an actual instance variable."
I guess it could be clearer... things always can. :)
To me, this implies that the name used in exposeBinding can differ
from
the iVar (and accessor) names.
There must be either an accessor or ivar with the same name as the
'exposed binding name'. But you are free to have an accessor like
this:
- (BOOL)isKeySlice
{
return someDumbName;
}
- (void)setIsKeySlice:(BOOL)flag
{
someDumbName = flag;
}
Thanks Sean; that really clears things up :)
I'm going to stick with keeping all names the same. Don't really want
to have 'proxy' accessors, but it's good to know I could go that route
if needed.
The real power of "binding names need not correspond" isn't just "use a
different name" but that you can have derived information bound and
automatically updated when the data it is derived from changes.
For example, if there are two integer ivars 'p' and 'q', you can have a
binding corresponding to {p,q} being a valid hyperbolic tessellation:
- (BOOL) isValidHyperbolicTessellation
{
return (p - 2) * (q - 2) > 4;
}
and if you have:
[self setKeys: [NSArray arrayWithObjects: @"p", @"q", NULL]
triggerChangeNotificationsForDependantKey:
@"isValidHyperbolicTessellation"];
in your classes +initialize method, and bind a text field with an error
message who's "hidden" property is bound to
"isValidHyperbolicTesselation" then setting p or q will automagically
update everything to cause the message to be hidden or not (or you
could have it return an error message as an NSString and bind to
that).
Glenn Andreas email@hidden
<http://www.gandreas.com/> oh my!
Mad, Bad, and Dangerous to Know
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden