Key- Value Table help required

Joined
Jun 3, 2011
Messages
54
Reaction score
0
Points
6
Hi all!!

I am looking for some data structure which will store data in terms of key and value and where one key corresponds to one or more than one value.

So , something like:

KEY VALUE
key1 value1
key1 value2
key1 value3
key2 value4
key2 value5
...... ..........

and on query all VALUE for a particular KEY is obtained in array.

I tried implementing NSDictionary but I am able to save on one to one basis only Multiple values for one ley is not possible.

Kindly help
 
OP
S
Joined
Jun 3, 2011
Messages
54
Reaction score
0
Points
6
or say that I have three keys (string type)like: key1,key2 and key3 and corresponding to each I have three arrays (NSarray type) array1, array2 and array3

So i want to map these as key and values:


key1 ---------> array1
key2----------> array2
key3----------> array3

So that from this structure, whenever VALUE for KEY (say key1) is queried, array1 (and so on) is returned.


Thanks in advance
 
Joined
Feb 25, 2009
Messages
2,112
Reaction score
71
Points
48
Your Mac's Specs
Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
If you're doing a single key refers to a single array, you can use an NSDictionary. NSDictionaries can contain NSArrays (or NSMutableArrays) - the problem arises if you want to use a single key to refer to multiple different arrays (which would make sense because then how would you know what array you really wanted?) which technically you still could do - You could have a key reference a mutable array in an ns dictionary, each entry in the mutable array is another array.

So it might look like:
Code:
Dict key1 ------------> Mutable Array of possibles
                                 |----> Mutable array 1
                                 |----> Mutable array 2
                                 |----> Mutable array 3
Dict key2 ------------> Mutable Array of possibles
                                 |----> Mutable array 1
                                 |----> Mutable array 2
                                 |----> Mutable array 3
Dict key3 ------------> Mutable Array of possibles
                                 |----> Mutable array 1
                                 |----> Mutable array 2
                                 |----> Mutable array 3

Of course, the other option is to use an SQLite database or CoreData
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top