Re: NSInvocation
Re: NSInvocation
- Subject: Re: NSInvocation
- From: "Sherm Pendley" <email@hidden>
- Date: Wed, 10 Sep 2008 03:24:40 -0400
On Wed, Sep 10, 2008 at 2:56 AM, Chris Idou <email@hidden> wrote:
>
> I have a need to call performSelector:withObject etc, except I need to pass
> 3 arguments. The doco to performSelector:withObject:withObject says to "See
> NSInvocation", which I have done, but I don't understand how to use it. Can
> anyone give me some code which implements performSelector:withObject etc as
> example?
Okay, let's assume we're sending a -hello: message to an instance
"theGreeter", with the string @"World!" as its argument, and a return value
of type int.
NSMethodSignature *sig = [theGreeter methodSignatureForSelector:
@selector(hello:)];
NSInvocation *invoker = [NSInvocation invocationWithMethodSignature: sig];
NSString *arg = @"World!";
int retVal = 0;
[invoker setSelector: @selector(hello:)];
[invoker setArgument: &arg atIndex:2]; // self and _cmd are at index 0 and 1
[invoker invokeWithTarget: theGreeter];
[invoker getReturnValue: &retVal];
All the usual caveats apply - typed into mail, untested, etc.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
_______________________________________________
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