开发者

How to get the array of all keys from the dictionary in the existing order? [duplicate]

开发者 https://www.devze.com 2023-03-04 03:14 出处:网络
This 开发者_开发百科question already has answers here: Closed 11 years ago. Possible Duplicate: How to sequentialy access a dictionary??
This 开发者_开发百科question already has answers here: Closed 11 years ago.

Possible Duplicate:

How to sequentialy access a dictionary??

I have a dictionary , I want to reitrive all keys in an array with the same order which exist inside the dictionary . The documentation on "allKeys" method of NSDictionary says the order of returned objects in array is not defined . What can be done to get the keys in the same order as that of the dictionary .

Thanks a lot in advance !!


So the question you were pointed to summarises the issue nicely, but the solutions offered could be a little bit too complex for your needs (if you didn't want / have the time to write a sub-class or your own data structure).

The quick and dirty alternative is simple to have an array that contains all the keys you want to access in the order you want to access them in. You can then simply match this array back to your dictionary to pull out values in the correct order.

0

精彩评论

暂无评论...
验证码 换一张
取 消