Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSDictionary to NSArray?

i have a NSDictionary which looks like:

{ "Item1" = 2.4; "Item2" = 5.5; "Item3" = 15.6; } 

To use this NSDictionary Items in a Table View i have to transfer it to a NSArray, am i right?

So i try:

NSDictionary *dict = [myDict objectForKey:@"items"];  for (id item in dict) {     [_myArray addObject:[dict objectForKey:item]]; } 

But _myArray keeps empty? What am i doing wrong?

like image 770
phx Avatar asked Feb 16 '10 15:02

phx


People also ask

What is NSDictionary in Swift?

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

What's a difference between NSArray and NSSet?

The main difference is that NSArray is for an ordered collection and NSSet is for an unordered collection. There are several articles out there that talk about the difference in speed between the two, like this one. If you're iterating through an unordered collection, NSSet is great.

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 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.


1 Answers

NSArray * values = [dictionary allValues]; 
like image 162
Dave DeLong Avatar answered Sep 23 '22 18:09

Dave DeLong