Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print keys of NSDictionary instead of values

I download some content from a json webservice.

Is it possible print the keys and not the values instead? For the eventuality of not knowing what the keys are.

like image 888
bruno Avatar asked Apr 10 '12 14:04

bruno


2 Answers

for( NSString *aKey in [dictionary allKeys] )
{
    // do something like a log:
    NSLog(aKey);
}

OR

NSLog([dictionary allKeys]);

This should do the trick

like image 143
Manuel Avatar answered Nov 11 '22 04:11

Manuel


You should be able to use the NSDictionary's keyEnumerator method to get the keys, then you can loop through them and print them out.

Borrowing an example from Apple:

NSEnumerator *enumerator = [myDictionary keyEnumerator];
id key;

while ((key = [enumerator nextObject])) {
    NSLog(@"Do something with the key here:%@",key);
}
like image 1
wtbgtr Avatar answered Nov 11 '22 05:11

wtbgtr