how do I put an object in a dictionary, change the object but leave the dict untouched?
how do I put an object in a dictionary, change the object but leave the dict untouched?
- Subject: how do I put an object in a dictionary, change the object but leave the dict untouched?
- From: "Alan Smith" <email@hidden>
- Date: Sat, 24 Jun 2006 15:20:20 -0400
I have a NSMutableDictionary (dict1) and am using another
dictionary(dict2) as the one I change and add to dict1. Dict2 has a
set of keys that change when the user changes some text fields. Each
entry of dict1 has a dict2 in it. One would assume that there would be
no problem in changing dict2 and then adding it another time to dict1.
Well, there is. Instead of leaving the other entries the same, they
all are changed to that of what I've changed dict2 to most recently.
Example:
//Assume the dictionaries exist
[dict2 setObject: @"some object" forKey: @"object"];
[dict1 setObject: dict2 forKey: @"firstEntry"];
[dict2 setObject: @"another object" forKey: @"object"];
[dict1 setObject: dict2 forKey: @"secondEntry"];
After the first time I add dict2 to dict1, dict1 will have a
dictionary with "some object" in it. The second time I add dict2 to
dict1, dict1 will have two dictionaries in it. But instead of a
dictionary with "some object" and another with "another object" it
will contain two dictionaries with "another object" in both.
I don't want to fill memory by creating another dictionary for each
time the user changes the text fields. What do I do?
Thanks, Alan
--
// Quotes from yours truly -------------------------
"You don't forget, you just don't remember."
"Maturity resides in the mind."
"Silence is the Universe's greatest gift."
"Don't waste your life doing things others have already done."
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden