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.
精彩评论