![](/img/trans.png)
[英]How to retrieve the values for the particular key from CFMutableDictionary
[英]Could not remove value from a CFMutableDictionary
我試圖使用CFDictionaryRemoveValue從字典中刪除鍵值對。 但是它並沒有刪除鍵和值,它也刪除了鍵值對。
struct session *value = CFDictionaryGetValue(cfmdict,tiId);
NSLog(@"The value is %d and %c", value->a, value->c);
CFDictionaryRemoveValue(cfmdict,tiId);
NSLog(@"The value is %d and %c", value->a, value->c);
The value is 12 and L
The value is 12 and L
該值不再在字典中,而是仍在內存中,並且value
仍指向該位置。 嘗試:
struct session *value = (struct session *)CFDictionaryGetValue(cfmdict,tiId);
NSLog(@"The value is %d and %c", value->a, value->c);
CFDictionaryRemoveValue(cfmdict,tiId);
value = (struct session *)CFDictionaryGetValue(cfmdict,tiId);
NSLog(@"The value is %d and %c", value->a, value->c);
看看會發生什么。
首次調用CFDictionaryGetValue
返回指向某個結構的指針。 然后,從字典中刪除指向該結構的指針,但這不會影響已經存儲在value
變量中的value
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.