Retrieve All Keys And Values Of An NSDictionary Object

If you ever need to collect all the values or all the keys of an NSDictionary object, there are methods in the dictionary class to provide the information as shown below.

Let’s start with a simple dictionary that contains three objects, an array, a string and a number:

// Create array
NSArray *array = [NSArray arrayWithObjects:
  @"String 1",
  [NSNumber numberWithInteger:99],
  [NSArray arrayWithObjects:
             @"array value 1",
             @"array value 2",
// Using literal style, add three objects
NSDictionary *dictionary = @{@"arrayKey" : array,
                             @"numberKey" : [NSNumber numberWithInt:25],
                             @"stringKey" : @"String value"};
NSLog(@"dictionary: %@", dictionary);

The dictionary looks as follows:
Continue reading