Re: NSInvocation question
Re: NSInvocation question
- Subject: Re: NSInvocation question
- From: Chris Suter <email@hidden>
- Date: Sat, 23 Feb 2008 12:47:22 +1100
On 23/02/2008, at 2:36 AM, Hank Heijink wrote:
The nice thing about NSInvocation is not so much its efficiency (or
lack thereof, as the case may be), but the fact that once you've got
the thing constructed, you can just call invoke on it, without
having to think about what's inside. I have functions of zero, one,
or two arguments that I wrapped up in NSInvocations. With IMPs, I
have to check the number of arguments both for the typing and for
the call.
However, even with the check for number of arguments, an IMP is very
very fast.
What you say here doesn't make sense to me. Without knowing exactly
what you're trying to do, it's difficult for me to comment. You can
arrange things so that it's simple without using NSInvocations. It
sounds like you've got some kind of delegate pattern, so the usual
Cocoa way of doing this is to pass a selector and a target around. For
example:
- (void)myCallBack1
{
/* You can call another method here with whatever arguments you
want. The arguments
would be stored as instance variables of the object. */
}
- (void)myCallBack2
{
// Likewise, you can call another method here with whatever
arguments you want
}
- (void)myCallBack3
{
// Do something
}
Elsewhere you'd have something like:
[myObject doSomethingWithDelegate:target selector:@selector
(myCallBack1)];
Then to make the callback you'd simply do:
[target performSelector:selector];
If you want to speed things up, you'd get and cache the IMP. That's
about as simple as doing [NSInvocation invoke] and there's no need to
be doing any checking of number of arguments.
Kind regards,
Chris
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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