簡體   English   中英

無法從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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM