Skip navigation.
 
mlRe: Key-Value pairs
FROM : Mike Abdullah
DATE : Mon Jun 02 23:49:45 2008

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.

Related mailsAuthorDate
mlKey-Value pairs john darnell Jun 2, 23:30
mlRe: Key-Value pairs Hamish Allan Jun 2, 23:41
mlRe: Key-Value pairs Mike Abdullah Jun 2, 23:49
mlRe: Key-Value pairs I. Savant Jun 3, 00:31
mlRe: Key-Value pairs Michael Ash Jun 3, 06:42
mlRe: Key-Value pairs Ken Thomases Jun 4, 03:05
mlRe: Key-Value pairs Graham Cox Jun 4, 03:39
mlRE: Key-Value pairs john darnell Jun 4, 18:43