Question

Does anyone know if the order of enumeration using enumerateKeysAndObjectsUsingBlock on a NSDictionary is defined? My experiments suggest that it's the same order as stuff was added, but I can't be 100% certain & I don't want it to break... Can't find anything anywhere which tells me.

Was it helpful?

Solution

the order is not defined at all. that is how a set acts and a dictionary is quite close to a sec...

to be sure the order is kept you have use a sortable property and when you get the keys, sort the resulting array

OR use a OrderedDictionary .... there is some implementation of that floating around on google but basically it is only a NSDictionary + an NSArray with the keys being in a stable order

a good one by cocoa heads

https://github.com/davedelong/CHDataStructures/blob/master/source/CHOrderedDictionary.h https://github.com/davedelong/CHDataStructures/blob/master/source/CHOrderedDictionary.m

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top