Re: NSInvocation
Re: NSInvocation
- Subject: Re: NSInvocation
- From: "Michael Ash" <email@hidden>
- Date: Wed, 10 Sep 2008 11:24:16 -0400
On Wed, Sep 10, 2008 at 11:13 AM, Ken Thomases <email@hidden> wrote:
> On Sep 10, 2008, at 9:52 AM, Michael Ash wrote:
>
>> And lastly, I recommend filing a bug against the documentation in this
>> case. NSInvocation is not really suited for this particular task, and
>> I don't understand why they would recommend it here.
>
> One possible reason is for proxying or otherwise handling unimplemented
> methods dynamically. There is a well-defined mechanism for what happens if
> you send a message to an object that doesn't directly implement a method for
> that message. A class can decide to forward the message, or it can do
> something funky in an override of doesNotRecognizeSelector:. That mechanism
> does kick in for performSelector:… and NSInvocation but doesn't for
> methodForSelector:.
Works fine for me:
#import <Cocoa/Cocoa.h>
@interface Foo : NSObject {} @end
@implementation Foo
- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel
{
NSMethodSignature *sig = [super methodSignatureForSelector:sel];
if(!sig) sig = [super methodSignatureForSelector:@selector(description)];
return sig;
}
- (void)forwardInvocation:(NSInvocation *)inv
{
NSLog(@"%s: %@", __func__, inv);
}
- (void)implemented
{
NSLog(@"%s", __func__);
}
@end
static void TestSel(SEL sel)
{
Foo *foo = [[Foo alloc] init];
[foo methodForSelector:sel](foo, sel);
[foo release];
}
int main(int argc, char *argv[])
{
[NSAutoreleasePool new];
TestSel(@selector(implemented));
TestSel(@selector(unimplemented));
return 0;
}
$ gcc -framework Cocoa test.m
$ ./a.out
2008-09-10 11:23:10.713 a.out[3913:10b] -[Foo implemented]
2008-09-10 11:23:10.739 a.out[3913:10b] -[Foo forwardInvocation:]:
<NSInvocation: 0x110a370>
$
Is there some other case where it would fail?
Mike
_______________________________________________
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