How to unarchive?
How to unarchive?
- Subject: How to unarchive?
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Thu, 28 Feb 2013 14:36:10 +0700
Assume I do:
ThingWhichKnowsItsContainer *a = [[ ThingWhichKnowsItsContainer alloc ] init];
NSArray *array = @[ a ];
a.theContainer = array;
NSData *d = [ NSKeyedArchiver archivedDataWithRootObject: array];
NSArray *unarchivedArray = [ MyVeryOwnUnarchiver: unarchiveObjectWithData: d ];
MyVeryOwnUnarchiver has a method like:
- (id)objectForArchiveIndex: (NSNumber *n)
{
id result = dictionaryOfThingsDone[n];
if ( result == nil ) // create and remember result
{
// assume n stands for the array:
NSMutableArray *tempMutable = [ NSMutableArray array];
dictionaryOfThingsDone[n] = tempMutable;
// needed to be done here so that later stuff (like ThingWhichKnowsItsContainer) do not create another array, but use this one.
for all archiveIndices "i" in "n" do:
{
id x = [ self objectForArchiveIndex: i ];
[ tempMutable addObject: x ];
}
result = [ tempMutable copy]; // result must be NSArray, not NSMutableArray
};
return result;
}
When it comes to ThingWhichKnowsItsContainer it will (using my dictionaryOfThingsDone) set myContainer = tempMutable.
So I get an unarchivedArray which contains a ThingWhichKnowsItsContainer which knows tempMutable but NOT it's container which is unarchivedArray.
How to fix this?
NSKeyedUnarchiver probably just uses something like: [tempMutable makeImmutable] but this is not a public method.
Gerriet.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden