0

Possible Duplicate:
Can i sort the NSDictionary on basis of key in Objective-C?

I have a several strings in a .plist file that I am trying to return into the NSDictionary then into an array but the order being returned isn't the same as I saved it in the playlist. So far I have tried

NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSArray *strs = [NSArray arrayWithArray:[dict allKeys]];
strs = [strs sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

but that is only returning the key names.

Community
  • 1
  • 1
Destiny Dawn
  • 1,457
  • 3
  • 15
  • 29
  • 6
    You can't order an NSDictionary, it is an inherently unordered object. You can order the keys like you did and loop through the ordered keys to get the values in that order, but that still doesn't order the dictionary. – rdelmar Oct 03 '12 at 22:27
  • http://stackoverflow.com/questions/8829119/getting-values-as-in-order-they-added-with-nsdictionary – vikingosegundo Oct 03 '12 at 22:38

2 Answers2

0

I actually was just looking through a few forums on google and found that this worked: Can i sort the NSDictionary on basis of key in Objective-C?

Community
  • 1
  • 1
Destiny Dawn
  • 1,457
  • 3
  • 15
  • 29
0

No, you can't.

You could keep an ordered array with your keys around as well, though.

Eiko
  • 25,601
  • 15
  • 56
  • 71