Re: Key-Value pairs
Re: Key-Value pairs
- Subject: Re: Key-Value pairs
- From: Mike Abdullah <email@hidden>
- Date: Mon, 2 Jun 2008 22:49:45 +0100
On 2 Jun 2008, at 22:30, john darnell wrote:
Hello everyone:
This is a discussion on theory and not a request for any practical
help.
Please also be advised I am not trying to bash Cocoa or Objective-C; I
am simply curious why the designers of same built the language the way
they did. Understanding theory can sometimes geometrically improve
performance.
I just read Hillegass' chapter that introduces Key-Value coding. To
refresh everyone's memory, key-value coding is the convention that
says
for every object the programmer defines, setting up a setter function
and a getter function as so:
/* Please note that I have really shortchanged the code so as not to
waste time or space with stuff we already know will be there.
Please also note that Outlook capitalizes lines behind my back and
be generous...*/
NSString *myString;
-(NSString *) myString
return myString;
- (void) setMyString:(NSString *) aString
myString = aString;
Is considered a good idea and is also a convention that ensures that
such objects like NSArrayController can work with your code with a
minimum of additional code. I am simplifying this horribly, I admit
and
will humbly bow to correction and chastisement if I have mis-stated
the
concept.
My question is, if this is such a necessary thing, why didn't the
designers simply design the compiler to auto-generate setter and
getter
functions as per the requisite style in the first place?
I would say this is because what you describe is a feature of ObjC,
whilst KVC is a convention of Cocoa. ObjC precedes Cocoa and so it's
not a standard practice the compiler is really aware of. However, with
ObjC 2.0 we now more-or-less have support for this.
Plus, often you want to add a little more custom code to the accessor,
but that's not all that good of a reason.
_______________________________________________
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