Re: Mixing Obj-C and C "methods"
Re: Mixing Obj-C and C "methods"
- Subject: Re: Mixing Obj-C and C "methods"
- From: Rick Mann <email@hidden>
- Date: Tue, 30 Jul 2013 01:19:08 -0700
On Jul 30, 2013, at 00:59 , Vincent Habchi <email@hidden> wrote:
> I have a very simple question: if I embed a C-function (more precisely, a callback from an external C-library) in an Obj-C object, can I expect this function to behave like a regular method? I.e. can it freely access ‘self’ and other attributes?
No; it'll be a stand-alone method with no implicit knowledge of the Objective-C class.
Having said that, most callback APIs allow you to pass a context parameter that gets passed back to your C callback. Often times, this context parameter is a void* you pass in along with a pointer to your callback function. You can pass "self" in this parameter when you register the callback, then cast it inside your callback back to MyClass* (or whatever your class is.
Precisely how you do this depends on the API you're using.
If it's a non-Apple API, it's much more likely they did it wrong and did not provide a context parameter.
What API are you using?
--
Rick
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden