Re: question about selector as argument
Re: question about selector as argument
- Subject: Re: question about selector as argument
- From: "Ivan S. Kourtev" <email@hidden>
- Date: Sat, 18 Jun 2005 11:53:57 -0400
Thanks, that did it!
-- ivan
On Jun 18, 2005, at 11:17 AM, Sherm Pendley wrote:
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
--
ivan (Ivan Kourtev) Assistant Professor, 348 Benedum Hall
Phone: 412.624.9088 Dept. of Electrical and Computer Engineering
Fax: 412.624.8003 University of Pittsburgh
Email: email@hidden Pittsburgh, PA 15261, USA
_______________________________________________
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