|
From: | Richard Frith-Macdonald |
Subject: | Re: Re[6]: Recent key-value encoding changes to NSObject. |
Date: | Mon, 11 Feb 2002 19:10:40 +0000 |
On Monday, February 11, 2002, at 05:54 PM, Manuel Guesdon wrote:
| I suggest that you do as follows in your custom subclass - |[...]| /* If there is an ivar, use it. */ | This should support all your needs - | | ivars take precedence over everything else. | dictionary values take precedence over getXXX. | getXXX are still used when all else fails.But getXXX should be called before ivar access (during the valueForKey process). :-(
Sorry if it sounds bad, but I think you are too close to this and need some perspective. Nicola just provided an example ... the point really is that you can quite easily do whatever you want to. If you want to use the private get methods first, that's fine.
so your method would be something like this - - (id) storedValueForKey: (NSString*) aKey { id result; if (private_get_method_exists(aKey) || private_ivar_exists(aKey)) return [super storedValueForKey: aKey]; result = [_values objectForKey: aKey]; if (result == nil) return [super storedValueForKey: aKey]; return result; } pretty simple really - and the code duplication with gstep-base would bethe stuff to test to see if a method or ivar exists ... simple string manipulation to make the appropriate names, and calls to respondsToSelector: or GSInstanceVariableInfo()
The only downside of doing it that way is a little inefficiency in testing some things twice in some cases - once in your implementation, and again in the superclass implementation.
[Prev in Thread] | Current Thread | [Next in Thread] |