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:

The dictionary looks as follows:

The dictionary class provides a method to store all the keys into an NSArray. The code below creates an array of keys and outputs the same to the console:

The output is below:

In a similar manner you can populate an array with all the values from the dictionary:

The output follows: