• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Mixing Obj-C and C "methods"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Mixing Obj-C and C "methods"
      • From: Andy Lee <email@hidden>
    • Re: Mixing Obj-C and C "methods"
      • From: Vincent Habchi <email@hidden>
References: 
 >Mixing Obj-C and C "methods" (From: Vincent Habchi <email@hidden>)

  • Prev by Date: Mixing Obj-C and C "methods"
  • Next by Date: Re: Mixing Obj-C and C "methods"
  • Previous by thread: Mixing Obj-C and C "methods"
  • Next by thread: Re: Mixing Obj-C and C "methods"
  • Index(es):
    • Date
    • Thread