Q:

How to modify array of dictionaries?

I have an NSArray with several NSDictionaries.  I want to create a new NSArray with the same number of NSDictionaries but I only want some keys in the dictionary, not all of the ones.
Example:
Array has 2 dictionaries.  Each dictionary has key name, age, address, email, phone.
I want new array that also has the 2 dictionaries, but only the name and address keys.

A:

I'd do something like:
NSMutableArray *replacementArray = [NSMutableArray array];

[existingArray enumerateObjectsUsingBlock:
    ^(NSDictionary *dictionary, NSUInteger idx, BOOL *stop)
    {
         NSDictionary *newDictionary = [NSDictionary dictionaryWithObjectsAndKeys:[dictionary objectForKey:@"name"], @"name", [dictionary objectForKey:@"address"], @"address", nil];
         [replacementArray addObject:newDictionary];
    }
];

