• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSInvocation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >NSInvocation (From: Chris Idou <email@hidden>)

  • Prev by Date: Multiple Document types
  • Next by Date: Re: While we're on the subject of DMG's for software distribution...
  • Previous by thread: NSInvocation
  • Next by thread: Re: NSInvocation
  • Index(es):
    • Date
    • Thread