Re: Archiving and Dearchiving
Re: Archiving and Dearchiving
- Subject: Re: Archiving and Dearchiving
- From: Chris Kane <email@hidden>
- Date: Sat, 29 Mar 2003 11:24:05 -0800
On Thursday, March 27, 2003, at 10:46 AM, email@hidden wrote:
If on the other hand I archive/dearchive using:
[NSKeyedArciver archiveRootObject: _myRootObject toFile:@"archive.bin"];
_myRootObject = [NSKeyedUnarchiver
unarchiveObjectWithFile:@"archive.bin"];
it works!
These two methods are the reverse of one another; if you use the
convenience method for archiving/unarchiving, you should use the
convenience method for unarchiving/archiving. That's why when you do
the encodeObject:withKey: yourself, the unarchiveObjectWithFile:
convenience method can't find the object in the archive.
Conversely, if you need to do the encodeObject:withKey: yourself, you
should use decodeObject:withKey:.
If you think about it, this makes sense. How would you write
archiveRootObject:toFile:? By creating an archiver and calling
encodeObject:withKey: and doing the rest of the stuff. Well, what is
the key that you pass as the key parameter? You pick something. The
unarchive convenience function then has to look for that same key.
In your original code, your key obviously doesn't match what the
unarchiver method is looking for.
It's not documented what the key for this root object is for these
convenience methods. Now, you can obviously look at an archive and
figure it out. But that key is not part of the API, so you risk your
app breaking in future releases if you use knowledge of that key. We
haven't made it part of the API because we're not sure we won't find it
desirable in a future release to change that key name for some reason.
And the only thing exporting that information would achieve is to allow
for mis-matched use of the convenience methods.
Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
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.