Nsdictionary in sorted list - MacRumors Forums
Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 15, 2008, 05:23 AM   #1
deepamalini
macrumors newbie
 
Join Date: Nov 2008
Nsdictionary in sorted list

Hi,

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?
deepamalini is offline   0 Reply With Quote
Old Dec 15, 2008, 12:49 PM   #2
xsmasher
macrumors regular
 
Join Date: Jul 2008
Quote:
Originally Posted by deepamalini View Post
Hi,

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?
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
Code:
keyIndex = [myKeys indexOfObject: keyIWant];
keyValue = [myValues objectAtIndex: keyIndex];
Anyone know a simpler solution? I'm assuming keyEnumerator doesn't preserver order.
xsmasher is offline   0 Reply With Quote
Old Dec 15, 2008, 11:32 PM   #3
deepamalini
Thread Starter
macrumors newbie
 
Join Date: Nov 2008
Hi,

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?
deepamalini is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: XML -> NSDictionary DennisBlah iPhone/iPad Programming 5 May 19, 2014 03:51 PM
Where do I initialise NSDictionary GerardGrundy iPhone/iPad Programming 9 Sep 8, 2013 10:04 PM
NSDictionary and NSUserNotification Question DavidBlack Mac Programming 7 Aug 19, 2013 12:43 AM
JSON and NSDictionary mngoose iPhone/iPad Programming 6 Jun 7, 2012 08:33 AM
Got my mac mini sorted serendipidy Mac mini 4 Jun 1, 2012 10:11 AM

Forum Jump

All times are GMT -5. The time now is 06:24 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC