开发者

Could not remove value from a CFMutableDictionary

开发者_如何转开发

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

output

The value is 12 and L
The value is 12 and L


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

And see what happens.


Your first call to CFDictionaryGetValue returns a pointer to some struct. Then you remove the pointer to this struct from the dictionary, but that doesn’t affect the value already stored in the value variable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜