How to remove key from nsmutabledictionary When value of that key is empty or null in ios?

Prasad G picture Prasad G · Jan 29, 2013 · Viewed 15.6k times · Source

I have created NSMutableDictionary and the values of keys are formed as nsarray. I have removed objects of keys. I have no doubt for this case. But I would like to remove key When value of that key is empty or null as following as the case.

{
    Africa =     (
        "Kenya",
        "South Africa"
    );
    America =     (
    );
    Asia =     (
        "India"
    );
}

The above dictionary has three keys and one of these keys has no objects that is America. I would like remove this key. Is it possible? Can we remove key from nsmutabledictionary?

Please help me.....

Edited: Simple mistake. I understand what i have mistaken. The key(America) has value and which is empty array that means the number of elements in array is zero.

Answer

user529758 picture user529758 · Jan 29, 2013

The above dictionary has three keys and one of these keys has no objects that is America.

FALSE. It holds an empty NSArray. This is how you remove it:

[dictionary removeObjectForKey:@"America"];