How does Cocoa implement delegate/callback?
How does Cocoa implement delegate/callback?
- Subject: How does Cocoa implement delegate/callback?
- From: Bill Cheeseman <email@hidden>
- Date: Thu, 14 Nov 2002 12:41:29 -0500
There are many Cocoa methods and functions, like NSBeginAlertSheet, that
give the user an option to pass a temporary delegate and a callback
selector. How does Cocoa implement this?
I ask because I would like to provide a similar option to clients of a class
I'm writing. A complicating factor is that the class I'm writing covers a C
API that expects the callback to be a C function. I want my clients to be
able to write their callbacks as Objective-C methods.
I suppose I can implement the C callback as a function in the class I'm
writing and register it with the C API. Then, when my C callback function is
triggered by the C API, I can have it send a message to my client's callback
selector. But how? Telling the delegate to
performSelector:withObject:withObject: won't work because the callback
method I specify has too many parameters. And I can't figure out how to get
NSInvocation to work.
Is this the best approach? If so, I'll keep digging.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
Croquet Club of Vermont -
http://members.valley.net/croquetvermont
_______________________________________________
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.