Nsdictionary in sorted list

macrumors newbie

I need to have a hashmap in my application. so i used nsdictionary. But i insert the key-value pair in nsdictionary in one order, What i get from nsdictionary is in different order. Is there a way to accompany to put key-value pair in some datatype and retreive from it in same order?

macrumors regular

I need to have a hashmap in my application. so i used nsdictionary. But i insert the key-value pair in nsdictionary in one order, What i get from nsdictionary is in different order. Is there a way to accompany to put key-value pair in some datatype and retreive from it in same order?

Click to expand...

It's unusual to need keys in order. Usually order = array, key/value = dictionary. Many ways to handle it, though.

(1) Keep an array of keys along with the dictionary. Then loop through the array and use the keys to get the values. (You'll have to add your own checks to keep the same key from appearing in the array twice.)

(2)You could keep an array of custom objects, one custom object for each pair (give the object .key and .value properites) . That's a very object-oriented way, but you lose the ability to easily find the value for a key (you have to loop through the array.)

(3)You could keep two arrays of strings, one for keys and one for values.
to find a value for a key, you just use

thread startermacrumors newbie

I cant use two data structure to accompany this. Because I am sending this key-value pair from the server, since i am handling with huge data, I cant send both arrays and dictionary from the server, it will slow done the process. Is there any other way?

MacRumors attracts a broad audience
of both consumers and professionals interested in
the latest technologies and products. We also boast an active community focused on
purchasing decisions and technical aspects of the iPhone, iPod, iPad, and Mac platforms.