开发者

CFDictionaryValueCallBacks retain/release?

开发者 https://www.devze.com 2023-01-07 16:22 出处:网络
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 CFT

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(CFAllocat开发者_JAVA技巧orRef 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消