tags:

views:

30

answers:

1

I would like to create an NSDictionary (or something similar) that has two keys per value. It will be for English/Spanish word look-up, where:

each value is an array containing all the conjugated verbs in English AND Spanish. each (two) keys contains both an English infinitive (e.g. "to be", "to go") and a Spanish infinitive

This way, I can look a word up regardless of language based on the values having two keys per value.

Here's an example:

keys: "to want" or "querer"

values: ["want", "want", "wants", "want", "want", "quiero", "quieres", "quiere", "queremos", "quieren"]

+3  A: 

Hello,

Just add the array with the conjugated verbs twice for the two different keys, the value is just a pointer to the array, so there is very little memory overhead. When you retrieve the value for "want" or "querer" you actually get the very same array which should be what you want.

Regards, Sebastian Mecklenburg

Sebastian Mecklenburg
Thanks Sebastian. Does this mean that I'll have to create seperate array variables for each of the verbs (e.g. NSArray *want = [[NSArray alloc] initWithObject ...etc...) or can I just alloc the array twice in the dictionary and it will still only use 1 space in memory?
Derek
@Derek: You do not need to create separate variables, and you definitely shouldn't create two separate arrays. You add the array to the dictionary once with the English key and again with the Spanish key. Same array both times. You can do it with the same variable.
Chuck
@Derek Chuck is right, don't alloc the array twice, do something like: NSArray *want = [[NSArray alloc] initWithObject...]; [dict setObject:want forKey:@"want"]; [dict setObject:want forKey:@"querer"]; (Sorry, comments don't seem to support code tags :-)
Sebastian Mecklenburg