Re: detecting keyedarchive data
Re: detecting keyedarchive data
- Subject: Re: detecting keyedarchive data
- From: Phill Kelley <email@hidden>
- Date: Sat, 30 Aug 2003 10:13:24 +1000
At 15:59 -0400 29/08/2003, Matthew Weinstein wrote:
>
I'm wanting to upgrade my file formats to use with keyedarchives. I
>
would like the transition to be invisible to my users: if they have
>
older versions, the program should read serial archives and when it
>
saves it will use a keyed format. The problem is that when opening
>
those files it may find itself confronted with the old format
>
(serial) or new format (keyed). Given an nsdata stream how can I tell
>
if it was archived with keys or not?
>
>
A thousand thanks in advance,
Assuming an object has a pair of accessors to set and retrieve its name,
you might proceed like this:
#define NameKey @"Name"
- (id) initWithCoder:(NSCoder*)coder
{
if ((self = [super init])) {
// are we using keyed archiving?
if ([coder allowsKeyedCoding]) {
// yes! proceed to do things in a keyed fashion
[self setName:[coder decodeObjectForKey:NameKey]];
// ...
} else {
// no! do things the old way
[self setName:[coder decodeObject]];
// ...
}
}
return self;
}
- (void) encodeWithCoder:(NSCoder*)coder
{
// are we using keyed archiving?
if ([coder allowsKeyedCoding]) {
// yes! proceed to do things in a keyed fashion
[coder encodeObject:[self name] forKey:NameKey];
// ...
} else {
// no! do things the old way
[coder encodeObject:[self name]];
// ...
}
}
Regards, Phill
--
----------------------------------------------
Phill Kelley
PO Box 661 Jamison Centre ACT Australia 2614
Voice: +61-2-6253-1015
Fax: +61-2-6253-4500
Mobile: +61-411-477-705
I am at UTC+10 (UTC+11 November through March)
_______________________________________________
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.