Re: NSArchiving and NSUnarchiving multiple objects
Re: NSArchiving and NSUnarchiving multiple objects
- Subject: Re: NSArchiving and NSUnarchiving multiple objects
- From: Jason Taylor <email@hidden>
- Date: Thu, 24 Feb 2005 10:31:53 -0500
Roarke Lynch wrote:
On Feb 24, 2005, at 8:42 AM, Jason Taylor wrote:
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];
When you archive a root object to file you aren't appending to the
file you specify, you are overwriting (unless I've read the docs
wrong). If you want to archive a series of objects into one file
you've got two simple options:
1) wrap then with a collection object (i.e. NSArray or
NSDictionary) and then archive that object as the root. Then when you
unarchive just pull out the objects you want and retain them
individually.
I think that I already have my objects wrapped up. I have an NSArray
of project objects and a separate NSArray of group objects. What code
would I need to archive those? Should I just put the two NSArrays into
another NSArray and archive that?
2) in whatever object class contains projects and groups as
instance variables implement NSCoding and then encode / decode that
instance as the root object.
I have a class called Manager that acts as the controller for my
application. It contains the two NSArrays, one of project objects and
one of group objects. It is the class that implements save and open. If
I make it NSCoding compliant, wouldn't I have to have another class
above it (with a Manager object as an iVar) to archive and unarchive it?
Or could I just create a Manager object and archive that?
Thanks for your help, I really appreciate it!
Roarke Lynch
-------------------------------
email@hidden
_______________________________________________
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