Migrating to keyed archiving...?
Migrating to keyed archiving...?
- Subject: Migrating to keyed archiving...?
- From: "Ben Kennedy" <email@hidden>
- Date: Thu, 13 Nov 2003 15:05:30 -0500
- Organization: Zygoat Creative Technical Services
Hi folks,
I feel like a bit of a dunce here, but I have a fundamental
implementation problem. Thanks to Panther's release, it's now time to
bring my app up to a minimum requirement of Jaguar. :) Accordingly, I'm
migrating all of my objects' archiving to use the keyed archiving mechanism.
The thing I can't figure out is how to alter my code such that it will
properly un-archive both old-school and new-school archive formats.
NSUnarchiver chokes on a file written out with NSKeyedArchiver
(understandably), and NSKeyedUnarchiver balks on old-school files written
out with NSUnarchiver. How do I handle pre-existing old-style files?
This is the hack that I'm now using, which seems to work:
ZDBSong *song;
NSData *d = [NSData dataWithContentsOfFile:filename];
if(!bcmp([d bytes], "\004\013typedstream", 13)) // old-school or new-
school?
song = [NSUnarchiver unarchiveObjectWithData:d]; // oldschool
else song = [NSKeyedArchiver unarchiveObjectWithData:d]; // newschool
[song retain];
This is ugly though. There must be a saner way. What am I missing?
(And please don't tell me I should be declaring a new file type, new file
extension, etc. for the new-school format...)
-ben
--
Ben Kennedy, chief magician
zygoat creative technical services
613-228-3392 | 1-866-466-4628
http://www.zygoat.ca
_______________________________________________
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.