Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display each item in an NSDictionary

I am trying to display each item in NSDictionary. I have tried using a for loop but that didn't work.

like image 797
alanvabraham Avatar asked Apr 08 '11 11:04

alanvabraham


People also ask

Does NSDictionary retain objects?

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

How do I create an NSDictionary in Objective-C?

Creating NSDictionary Objects Using Dictionary Literals In addition to the provided initializers, such as init(objects:forKeys:) , you can create an NSDictionary object using a dictionary literal. In Objective-C, the compiler generates code that makes an underlying call to the init(objects:forKeys:count:) method.

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.

What is a NSDictionary object?

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


2 Answers

Try this code

for(NSString *key in [dict allKeys]) {   NSLog(@"%@",[dict objectForKey:key]); } 
like image 102
PgmFreek Avatar answered Oct 17 '22 18:10

PgmFreek


What about

NSLog(@"Dictionary: %@", [myDictionary description]); 

Seems to work for me...

like image 20
Nick Avatar answered Oct 17 '22 18:10

Nick