![](/img/trans.png)
[英]Implicit conversion of a non-Objective-C pointer type 'void *' to '__unsafe_unretained id *' is disallowed with ARC
[英]Casting '__unsafe_unretained id *' to 'const void **'
我正在嘗試使用CFDictionary實現[NSMutableDictionary dictionaryWithObjects:frames forKeys:items]
,因此我可以控制鍵和值回調。 這就是我得到的:
__unsafe_unretained id keys[itemCount];
[items getObjects:keys range:NSMakeRange(0, itemCount)];
__unsafe_unretained id values[itemCount];
[frames getObjects:values range:NSMakeRange(0, itemCount)];
CFDictionaryCreate(kCFAllocatorDefault, (const void **)keys, (const void **)values, itemCount, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
這將導致以下錯誤: Cast of an indirect pointer to an Objective-C pointer to 'const void **' is disallowed with ARC
。
我已經嘗試了各種橋接方法,但是我似乎無法毫無抱怨地編譯它。
任何幫助,不勝感激!
我也無法為此找到語法。 (編輯:賈斯汀的答案具有語法。)嘗試以下操作:
void *keys[itemCount];
[items getObjects:(__unsafe_unretained id *)(void *)keys range:NSMakeRange(0, itemCount)];
然后,當您調用CFDictionaryCreate
時就不需要CFDictionaryCreate
。
您可以在此時將其簡單地轉換為void*
:
CFDictionaryRef d = CFDictionaryCreate(kCFAllocatorDefault,
(void*)keys,
(void*)values,
itemCount,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
您也可以考慮以下方法:
const void* keys[itemCount];
CFArrayGetValues((__bridge CFArrayRef)items, CFRangeMake(0, itemCount), keys);
const void* values[itemCount];
CFArrayGetValues((__bridge CFArrayRef)frames, CFRangeMake(0, itemCount), values);
CFDictionaryRef d = CFDictionaryCreate(kCFAllocatorDefault,
keys,
values,
itemCount,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
嘗試(__bridge const void **)keys
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.