Re: question about selector as argument
Re: question about selector as argument
- Subject: Re: question about selector as argument
- From: Sherm Pendley <email@hidden>
- Date: Sat, 18 Jun 2005 11:17:28 -0400
On Jun 18, 2005, at 9:34 AM, Ivan S. Kourtev wrote:
I was able to get this to work by modifying the callback to take an
NSNumber* argument, then using performSelector:withObject within
but doSomething. But I am sure there must be another way to do
what I want.
...
- (void)doSomething:(id)anObject withCallBack:(SEL)aSelector {
...
[anObject aSelector:10];
...
}
As you've discovered, this doesn't work - it simply looks for a
method named aSelector:. And, as you've also found,
performSelector:withObject:, as its name implies, only works with
object arguments. What's left is NSInvocation. You can use that to
build up any argument list and pass it. For instance:
- (void)doSomething:(id)anObject withCallBack:(SEL)aSelector {
NSMethodSignature* sig = [anObject
methodSignatureForSelector:aSelector];
NSInvocation *inv = [NSInvocation
invocationWithMethodSignature:sig];
int theArg = 10;
[inv setTarget:anObject]; // "Hidden" arg 0, self
[inv setSelector:aSelector]; // "Hidden" arg 1, _cmd
[inv setArgument:&theArg atIndex:2];
[inv invoke];
}
sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden