Re: (SEL) and @selector questions
Re: (SEL) and @selector questions
- Subject: Re: (SEL) and @selector questions
- From: Sherm Pendley <email@hidden>
- Date: Fri, 28 Feb 2003 18:07:39 -0500
On Friday, February 28, 2003, at 09:37 AM, Jirome Foucher wrote:
Here's a question about Objective-C to which I haven't found the answer
in the books I have....
I have a function which takes a selector parameter :
- (id)initWithFileSystemItem:(id <FileSystemItemSkeleton>)it
arguments:(NSArray *)args postProcess:(SEL)postp
postp is the selector of the method I need to call when some data has
been computed.
It's a function that belongs to FileSystemItemSkeleton.
But how do I call the post-processor method when the computed data is
complete and needs to be transfered ?
Others have pointed out the simple way - use NSObject's performSelector:
method.
A more flexible way to do it - the only way, if the callback method
takes more than a single object as its argument, or returns anything -
is to use an NSInvocation.
To create the NSInvocation object, you need an NSMethodSignature - you
can get one by sending methodSignatureForSelector: to the object that is
to be the target - that is, to "it" above.
Then you use NSInvocation's setTarget: and setArgument:atIndex: methods,
its invoke: method, and finally (if you want the return value), its
getReturnValue: method.
sherm--
UNIX: Where /sbin/init is Job 1.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.