我可以将CFMutableDictionaryRef转换为CFDictionaryRef吗?

问题描述 投票:0回答:1

函数期望返回CFDictionaryRef:

CFDictionaryRef xyz()
{
CFMutableDictionaryRef test = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(test, CFSTR("Test"), CFSTR("Test"));

return reinterpret_cast<CFDictionaryRef>(test);
}

可以使用reinterpret_cast进行转换吗?向我抛出一个空的ptr。

c++ ios objective-c core-foundation reinterpret-cast
1个回答
0
投票

您可以安全地进行以下操作:

CFDictionaryRef xyz()
{
    CFMutableDictionaryRef test = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    CFDictionarySetValue(test, CFSTR("Test"), CFSTR("Test"));

    return (CFDictionaryRef)test;
}
© www.soinside.com 2019 - 2024. All rights reserved.