Re: key value coding sample code
Re: key value coding sample code
- Subject: Re: key value coding sample code
- From: Sherm Pendley <email@hidden>
- Date: Sat, 7 Dec 2002 22:24:19 -0500
On Saturday, December 7, 2002, at 09:44 PM, Matthew Lehrian wrote:
So, in summary, valueForKey: and takeValue:forKey: actually do this:
1) Check for appropriate accessor or mutator and call that method
2) If not found, check for appropriate iVar and set or return that
value
You've left out a couple of steps. Assuming a key named "foo":
1. Search for a public accessor method, named setFoo:, getFoo, or foo.
2. Search for a private accessor method, named _setFoo:, _getFoo: or
_foo.
3. Look for an iVar named either foo or _foo.
4. Look for handleQueryWithUnboundKey: or handleTakeValue:forUnboundKey
methods.
The methods takeStoredValue:forKey: and storedValueForKey: are similar,
but prefer private accessors and direct access to iVars over public
accessors. In other words, they take the above steps in the order
2,3,1,4.
Note that the "stored" variants are the default, so public
accessors/mutators offer less than optimal performance. If you'd like
the KVC mechanism to use the public-oriented methods instead, implement
the class method useStoredAccessor, and have it return NO.
Finally, if you want to disable direct access to iVars and require
accessor/mutator methods, implement the class method
accessInstanceVariablesDirectly, and have it return NO.
This is all explained in greater detail in:
file:///Developer/Documentation/Cocoa/TasksAndConcepts/ProgrammingTopics/KeyValueCoding/
index.html
sherm--
If you listen to a UNIX shell, can you hear the C?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.