开发者

Avoiding sorting in NSDictionary

开发者 https://www.devze.com 2022-12-27 10:29 出处:网络
I was using NSDictionary and I observed that the objects in the dictionary are sorted automatically with respect to the keys, so my question is how to avoid this sorting, any flag available to set it

I was using NSDictionary and I observed that the objects in the dictionary are sorted automatically with respect to the keys, so my question is how to avoid this sorting, any flag available to set it off, so I get the object in same order I entered.

I know you may be thinking what difference it makes in dictionary since we retrieve the value with respect to key, but I am first getting allKeys from which I receive Array of keys, this order is what I need it to be in th开发者_如何转开发e order of how I entered just as in NSArray.


I guess that there will not be a method to control the sorting in NSDictionary, because 'NSDictionary' is a hash table which uses hash function to chose the place to store the values(for speedy accessing).

To customize dictionary you can use CFDictionaryRef there you can write your custom callback. You can write your own CFDictionaryHashCallBack function to compute the place for storing. CFDictionary is "toll-free bridged" with NSDictionary.

Regards
Devara Gudda

0

精彩评论

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

关注公众号