Display each item in an NSDictionary

44,018

Solution 1

Try this code

for(NSString *key in [dict allKeys]) {
  NSLog(@"%@",[dict objectForKey:key]);
}

Solution 2

What about

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

Seems to work for me...

Solution 3

This works for me and is very useful for debugging.

NSDictionary *jsonDictionary = [theJSON JSONValue];

NSLog(@"dictionary data %@",jsonDictionary);
Share:
44,018

Related videos on Youtube

alanvabraham
Author by

alanvabraham

mobile application development enthusaist

Updated on July 09, 2022

Comments

  • alanvabraham
    alanvabraham almost 2 years

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

  • Aniket Thakur
    Aniket Thakur almost 6 years
    Better to add key in NSLog as well. You can do - ` NSLog(@"%@ : %@",key, [dict objectForKey:key]); `
  • Alex Meuer
    Alex Meuer over 5 years
    Since this answer was written, new syntax has become available. You can now do NSLog(@"%@", dict[key]); if you prefer..

Related