NSArchiving and NSUnarchiving multiple objects
NSArchiving and NSUnarchiving multiple objects
- Subject: NSArchiving and NSUnarchiving multiple objects
- From: Jason Taylor <email@hidden>
- Date: Thu, 24 Feb 2005 08:42:39 -0500
Hi,
I am developing an application that contains two arrays, one
contains one type of objects (projects) and another contains a different
type of objects (groups). I had implemented the NSCoding protocol in my
projects class and had used NSArchiver and NSUnarciver objects to save
the array of project objects to a file and open them back up. This
worked great... until I decided that I wanted to archive another array
of different objects (groups) into the same file. I call NSArchiver
archiveRootObjects on the array of project objects and then call it on
the array of groups. It saves just fine. I then use NSUnarciver to
unarchive them in the same order that I saved them, but I only get the
data from the last array that was archived. I don't know what I need to
do to archive and unarchive the objects into their proper arrays. Here
is some code:
From my save method:
// This one worked fine by itself
[NSArchiver archiveRootObject:projects toFile:currentDocument];
// This one is causing the problem, although the save executes just
fine without errors
[NSArchiver archiveRootObject:groups toFile:currentDocument];
From my open method:
// For my project objects
NSMutableArray * array;
// For my group objects
NSMutableArray * groupsArray;
// This worked fine by itself
array = [NSUnarchiver unarchiveObjectWithFile:[sheet filename]];
groupsArray = [NSUnarchiver unarchiveObjectWithFile:[sheet filename]];
[array retain];
[groupsArray retain];
[projects release];
[groups release];
projects = array;
groups = groupsArray;
Once this code is executed, both array, and groupsArray have the same
objects in them (from the originally saved array of group objects),
which they should not. It seems as if it can't figure out the boundary
between one array and the other. Does anyone know how I can fix this?
_______________________________________________
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