无法从CFMutableDictionary中删除值 [英] Could not remove value from a CFMutableDictionary

查看:108
本文介绍了无法从CFMutableDictionary中删除值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用CFDictionaryRemoveValue从字典中删除键值对. 但是它并没有删除键和值.它也删除了键和值对.

I was trying to remove a key value pair from the dictionary with CFDictionaryRemoveValue. But its not removing the keys and values.Its printng me the key-value pairs after removing too.

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仍指向该位置.试试:

The value is not in the dictionary anymore, but still in memory, and value still points there. Try:

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);

看看会发生什么.

这篇关于无法从CFMutableDictionary中删除值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆