• 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: Andy Lee <email@hidden>
  • Date: Tue, 30 Jul 2013 11:00:06 -0400

On Jul 30, 2013, at 4:27 AM, Vincent Habchi <email@hidden> wrote:
> 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 *.

A couple of alternatives, just for your consideration in case they hadn't occurred to you.

One alternative would be to use __unsafe_unretained.  ARC allows structs like this:

typedef struct _MyStruct {
    __unsafe_unretained id myObj;
} MyStruct;

So you'd be able to access the myObj member of the struct without having to cast.  But you'd have to make sure myObj doesn't get dealloc'ed before the struct is used (i.e., before the callback is invoked), so maybe you wouldn't be doing any less work code-wise.

Apple's recommended alternative to having a struct contain an object is to use a class instead of a struct.  You could create a MyCallbackInfo class with two properties: the query id and the pointer to self.  You'd still have to bridge-cast *that* object when passing it to the callback.

--Andy


_______________________________________________

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: Vincent Habchi <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>)
 >Re: Mixing Obj-C and C "methods" (From: Vincent Habchi <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