Prasad G
Prasad G

Reputation: 6718

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

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.

Upvotes: 8

Views: 16868

Answers (3)

Berlin
Berlin

Reputation: 2227

in swift 3.0

dictionary.removeObject(forKey: "America")

Upvotes: 0

Anoop Vaidya
Anoop Vaidya

Reputation: 46543

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

This is not possible, dictionary must have Key and Value a non-nil Value.

In your case it is Array. that contains no value.

EDIT:

Whenever you see { }, that is dictionary, & ( ) is array.

Upvotes: 3

user529758
user529758

Reputation:

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"];

Upvotes: 30

Related Questions