Objective-C Language NSMutableDictionary Removing Entries From a Mutable Dictionary


Example

- removeObjectForKey:

Removes a given key and its associated value from the dictionary.

NSMutableDictionary *dict =  [NSMutableDictionary dictionaryWithDictionary:@{@"key1":@"Easy",@"key2": @"Tutorials"}];
[dict removeObjectForKey:@"key1"];
NSLog(@"%@",dict);

OUTPUT

{
    key2 = Tutorials;
} 

- removeAllObjects

Empties the dictionary of its entries.

NSMutableDictionary *dict =  [NSMutableDictionary dictionaryWithDictionary:@{@"key1":@"Eezy",@"key2": @"Tutorials"}];
[dict removeAllObjects];
NSLog(@"%@",dict);

OUTPUT

{
}

- removeObjectsForKeys:

Removes from the dictionary entries specified by elements in a given array.

NSMutableDictionary *dict =  [NSMutableDictionary dictionaryWithDictionary:@{@"key1":@"Easy",@"key2": @"Tutorials"}];
[dict removeObjectsForKeys:@[@"key1"]];
NSLog(@"%@",dict);

OUTPUT

{
    key2 = Tutorials;
}