문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top