FROM : Chris Suter
DATE : Sat Feb 23 02:47:22 2008
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
DATE : Sat Feb 23 02:47:22 2008
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
| Related mails | Author | Date |
|---|---|---|
| Hank Heijink | Feb 21, 17:22 | |
| Nir Soffer | Feb 22, 01:42 | |
| Hank Heijink | Feb 22, 05:00 | |
| Chris Suter | Feb 22, 05:18 | |
| Hank Heijink | Feb 22, 16:36 | |
| Chris Suter | Feb 23, 02:47 | |
| Hank Heijink | Feb 25, 15:49 | |
| Nir Soffer | Feb 25, 21:30 | |
| Hank Heijink | Feb 25, 21:44 | |
| Nir Soffer | Feb 25, 21:49 | |
| Hank Heijink | Feb 25, 22:51 | |
| Chris Suter | Feb 26, 00:03 | |
| Hank Heijink | Feb 27, 16:58 |






Cocoa mail archive

