Re: Key Archiving a NSMutableDictionary object corrupts its embedded NSMutableDictionary data object
Re: Key Archiving a NSMutableDictionary object corrupts its embedded NSMutableDictionary data object
- Subject: Re: Key Archiving a NSMutableDictionary object corrupts its embedded NSMutableDictionary data object
- From: "Martin" <email@hidden>
- Date: Mon, 05 Jul 2004 17:39:48 -0700
Hi Frederick,
I have also encountered this problem when archiving NSMutableDictionary objects. My dictionary mapped NSNumber objects to a custom class I had written.
What works for me is to simply make an immutable copy of the dictionary for serialization, eg:
NSDictionary* map = [mutableMap copy];
[coder encodeObject:map forKey:@"key"];
[map release];
And on deserialization:
map = [c decodeObjectForKey:@"key"];
mutableMap = [map mutableCopy];
I realize this is not the most efficient, but the only thing that worked for me in the end. Best,
~Martin
On July 04 2004, Frederick C. Lee <email@hidden> wrote:
>
Greetings:
>
>
The scenario:
>
>
I'm trying to archive a NSMutableDictionary of country objects, the
>
key being the country name. Each country object (model) contains
>
assorted country-related instance variables, including an embedded
>
NSMutableDictionary of city objects that are roughly patterned the same
>
way as their parent country.
>
>
>
{Country Dictionary}
>
['country name' --> (country object)]
>
{City Dictionary}
>
['city name' -->(city
>
object)]
>
...
>
...
>
>
>
I'm using key-archiving to store the country dictionary.
>
>
Problem: The embedded city dictionary always returns corrupt. Or
>
perhaps is written corrupted before the read. However, I'm able to
>
read the keys of the apparent corrupted NSMutableDictionary.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.