I understand that the right way to sort an NSDictionary is to create an array from the keys, sort the array, and then enumerate through the array and operate on the NSDictionary from there. My question is, for an NSDictionary *dict, with keys and values of strings,
Why is this alphabetical:
NSLog(@"%@", dict);
But this is not:
for (NSString *w in dict)
{
NSLog(@"%@", w);
}
Seems odd… am I doing something wrong?
Thanks in advance.
That’s not “in memory” — %@ causes a message to be called on dict, and that sorted it. Enumerating is meant to give you the fastest, raw access to the contents. If you need it sorted, you have to sort it.
Take a look at this free sorted dictionary for Objective-C
http://code.google.com/p/cocoa-sorted-dictionary/