看板 MacDev 關於我們 聯絡資訊
大家好 我現在在看別人寫的code 程式中有一部分是使用c將一些資料以CFDictionaryRef格式儲存 參考CFDictionaryRef的說明 https://developer.apple.co1m/library/mac/documentation/ corefoundation/Reference/CFDictionaryRef/Reference/reference.html 並參考別人的用法 http://pastebin.com/qAtbBraA const void * keys; const void * values; CFDictionaryGetKeysAndValues(cfdref, &keys, &values); for (int i = 0 ; i < CFDictionaryGetCount(cfdref); i++) { CFStringRef x = (CFStringRef)&keys[i]; CFStringRef y = (CFStringRef)&values[i]; } 在for 迴圈裡面的兩個assign都會出現下述錯誤 Subscript of pointer to incomplete type 'const void' 想請教一下 該怎麼寫才是正確的把CFDictionaryRef的key與value 轉成CFStringRef的方式呢 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.59.147.226 ※ 文章網址: http://www.ptt.cc/bbs/MacDev/M.1396862087.A.646.html
atst2:跑過了很正常...我想你可能只是拚錯字之類的錯誤吧? 04/07 18:43
atst2:要不要再檢查一下? 04/07 18:43
uranusjr:CFDictionaryGetKeysAndVlues <-- 最後面少一個 a XD 04/07 22:16
阿 我key來PTT時打錯^^;
donkeychen:QQ 奇怪; xcode會跳紅色錯誤 04/08 09:46
後來改成 CFIndex count = CFDictionaryGetCount(cfdref); const CFStringRef* pname = new CFStringRef[count]; const CFStringRef* pvalue = new CFStringRef[count]; CFDictionaryGetKeysAndValues(cfdref, (const void**)pname, (const void**)pvalue); for (CFIndex i = 0; i < count; i++) { CFStringRef x = pname[i]; CFStringRef y = pvalue[i]; } delete[] pname; delete[] pvalue; 才compile過... (compiler是GCC 4.2 xcode4.02 4a2002a) 有解決了 感謝大家:) ※ 編輯: donkeychen (210.59.147.226), 04/08/2014 09:53:19
atst2:手邊沒有xcode4, 不過xcode5用clang是ok的 04/08 10:18
atst2:不太能確定是否是編譯版本的差異造成的. 04/08 10:19
donkeychen:恩恩 感謝 ^^ 04/08 15:15