[問題] CFDictionaryRef 轉換成 CFString 問題

看板MacDev作者 (Bad_To_The_Bone)時間11年前 (2014/04/07 17:14), 11年前編輯推噓0(007)
留言7則, 3人參與, 最新討論串1/1
大家好 我現在在看別人寫的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

04/07 18:43, , 1F
跑過了很正常...我想你可能只是拚錯字之類的錯誤吧?
04/07 18:43, 1F

04/07 18:43, , 2F
要不要再檢查一下?
04/07 18:43, 2F

04/07 22:16, , 3F
CFDictionaryGetKeysAndVlues <-- 最後面少一個 a XD
04/07 22:16, 3F
阿 我key來PTT時打錯^^;

04/08 09:46, , 4F
QQ 奇怪; xcode會跳紅色錯誤
04/08 09:46, 4F
後來改成 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

04/08 10:18, , 5F
手邊沒有xcode4, 不過xcode5用clang是ok的
04/08 10:18, 5F

04/08 10:19, , 6F
不太能確定是否是編譯版本的差異造成的.
04/08 10:19, 6F

04/08 15:15, , 7F
恩恩 感謝 ^^
04/08 15:15, 7F
文章代碼(AID): #1JGco7P6 (MacDev)
文章代碼(AID): #1JGco7P6 (MacDev)