|
From: | Richard Frith-Macdonald |
Subject: | Re: Re[6]: Recent key-value encoding changes to NSObject. |
Date: | Mon, 11 Feb 2002 19:29:02 +0000 |
On Monday, February 11, 2002, at 06:17 PM, Manuel Guesdon wrote:
| Option 2 ... as I described before, modify a few standard methods | somewhat like this - | | - (BOOL) respondsToSelector: (SEL)aSel | { | BOOL result = [super respondsToSelector: aSel]; | | if (result == NO && this_is_a_private_get_method(aSel)) | return YES; | | return result; | } | | - (NSMethodSignature*) methodSignatureForSelector: (SEL)aSel | {| NSMethodSignature *sig = [super methodSignatureForSelector: aSel];| | if (sig == nil && this_is_a_private_get_method(aSel)) | return signature_of_method; | | return imp; | } | | - (IMP) methodForSelector: (SEL)aSel | { | IMP imp = [super methodForSelector: aSel]; || if (imp == forwarding_method && this_is_a_private_get_method(aSel))| return get_method; | return imp; | } | | - (id) theGetMethod | {| // examine _cmd and fetch the appropriate value from the dictionary.| }I'n not sure I follow your demonstration :-) The "theGetMethod" is my "x -(id)a" method ?If yes, this is not good since "user" can't just put "|self storedValueForKey:@"..."] in it.
No. it would do something like this (actually, for performance you would probably use the objc runtime method sel_get_name() (I think) to get a cString and manipulate that ... only converting to an NSString
to use as the dictionary key). - (id) theGetMethod { NSString *key = NSStringFromSelector(_cmd); if ([key hasPrefix: @"_"] == YES) key = [key substringFromIndex: 1]; return [_values objectForKey: key]; }
[Prev in Thread] | Current Thread | [Next in Thread] |