views:

22

answers:

1

Is there a constant retain callback I can use for generic id / NSObjects ? There is kCFTypeDictionaryValueCallBacks but they're only for "CFType-derived objects." I don't believe NSObjects are CFTypes, so I wrote these:

const void *valueRetainCallBack(CFAllocatorRef allocator, const void *ptr)
{
    id o = (id)ptr;
    [o retain];

    return o;
}

void valueReleaseCallBack(CFAllocatorRef allocator, const void *ptr)
{
    id o = (id)ptr;
    [o release];
}

But perhaps there is a simpler way?

+2  A: 

Is there a constant retain callback I can use for generic id / NSObjects ? There is kCFTypeDictionaryValueCallBacks but they're only for "CFType-derived objects." I don't believe NSObjects are CFTypes…

They're not documented as fully bridged, but for memory management (retain and release), that's documented to work. In practice, all the functions common to CFType and NSObject, including description/CFCopyDescription, work as well.

Peter Hosey