• 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: Vincent Habchi <email@hidden>
  • Date: Tue, 30 Jul 2013 10:27:34 +0200

Rick,

thanks for answering, because what I found on the Internet seems contradictory. Some say that if the C function is placed inside the implementation block, then it can access attributes as if it were a true Obj-C method; some say otherwise. So it’s a bit difficult to find a definitive answer thereon.

> 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).

Yes, right; it’s a SQLite callback, the first parameter is a void *. I wanted to pass a pointer to a structure containing both a unique query id (out of uuid) and a pointer to self, but got told off by ARC because it apparently forbids to embed pointers to Obj-C objects in C-structs. So I just bridge-cast it to void *.

Assuming the pointer to the struct is named ‘info’ and the field containing a reference to ‘self’ is called ‘this’, [info->this someMethod] as well as info->this->someAttribute are legal, aren’t they?

Thanks a lot!
Vincent


_______________________________________________

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: Jean-Daniel Dupas <email@hidden>
    • Re: Mixing Obj-C and C "methods"
      • From: Rick Mann <email@hidden>
References: 
 >Mixing Obj-C and C "methods" (From: Vincent Habchi <email@hidden>)
 >Re: Mixing Obj-C and C "methods" (From: Rick Mann <email@hidden>)

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