Please tell me how can we have multiple values for the same key in NSMutableDictionary?
When I use the below approach, the values are being replaced with the recent one.
In my case:
[dictionary setObject:forename forKey:[NSNumber numberWithint:code]];
[dictionary setObject:surname forKey:[NSNumber numberWithint:code]];
[dictionary setObject:reminderDate forKey:[NSNumber numberWithint:code]];
When I view the contents of the dictionary, I get only the reminderDate for key code. Here, the code is same for all values. How do I avoid forename and surname being replaced by plannedReminder.
Thank You!
It seems like you are using
codeas the key and you want to represent multiple values based oncode. In that case, you should either:Abstract all data associated with
codeinto a separate class (perhaps calledPerson) and use instances of this class as values in the dictionary.Use more than one layer of dictionaries: