Zhen
Zhen

Reputation: 12431

How to retrieve all keys from a dictionary?

How can I retrieve all the keys (only) from a NSDictionary? I do not need them in any particular order.

Upvotes: 1

Views: 7485

Answers (2)

Faizan S.
Faizan S.

Reputation: 8644

Use the allKeys method on your NSDictionary.

From the docs:

allKeys : Returns a new array containing the dictionary’s keys.

- (NSArray *)allKeys    

Return Value

A new array containing the dictionary’s keys, or an empty array if the dictionary has no entries.

Upvotes: 17

Sandro Meier
Sandro Meier

Reputation: 3051

I advise you to study the Dokumentation. ;-) Take a look here:

- (NSArray *)allKeys;

From the Dokumentation:

Returns a new array containing the dictionary’s keys.

  • (NSArray *)allKeys

Return Value A new array containing the dictionary’s keys, or an empty array if the dictionary has no entries.

Discussion The order of the elements in the array is not defined.

Upvotes: 0

Related Questions