in my project I’m pulling data from a .plist, more concretely from an NSDictionary. I init a dictionary with the contents of the .plist, which works well.
When I then do
NSArray *array = [dict allKeys];
it fills the array with all the keys, but in a totally random order, different to the order they are in the .plist file. I would really need to preserve the order.
The keys in the dictionary are arrays, if that could cause a problem.
What am I not getting?
Thanks a lot in advance!
Much like there is no order between items in an NSSet, there’s is no inherent order to the key-value pairs within an NSDictionary.
If you want keys under a specific order, you’d need to use something like
- (NSArray *)keysSortedByValueUsingComparator:(NSComparator)cmptrbut that won’t give the order in which the NSDictionary was serialized in the plist file.