Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all keys of an NSDictionary as an NSArray

Is it possible to get all the keys from a specific NSDictionary as a seperate NSArray?

like image 522
Jay Avatar asked Aug 14 '11 13:08

Jay


People also ask

What is the difference between NSMapTable vs NSDictionary?

NSDictionary / NSMutableDictionary copies keys, and holds strong references to values. NSMapTable is mutable, without an immutable counterpart. NSMapTable can hold keys and values with weak references, in such a way that entries are removed when either the key or value is deallocated.

Does NSDictionary retain objects?

An NSDictionary will retain it's objects, and copy it's keys.

What is the difference between NSDictionary and NSMutableDictionary?

Main Difference is:NSMutableDictionary is derived from NSDictionary, it has all the methods of NSDictionary. NSMutableDictionary is mutable( can be modified) but NSDictionary is immutable (can not be modified).

What is NSDictionary?

An object representing a static collection of key-value pairs, for use instead of a Dictionary constant in cases that require reference semantics.


1 Answers

Just use

NSArray*keys=[dict allKeys]; 

In general, if you wonder if a specific class has a specific method, look up Apple's own documentation. In this case, see NSDictionary class reference. Go through all the methods. You'll discover many useful methods that way.

like image 137
Yuji Avatar answered Sep 28 '22 02:09

Yuji