On Jul 30, 2013, at 4:27 AM, Vincent Habchi <vi...@macports.org> 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to