Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSUnarchiver question



Actually, there is versioning support in NSArchiver. You set the class version using :

+ (void)initialize
{
if(self == [MyClass class])
{
// v1 -> feature added
[self setVersion:1];
}
}

Then implement NSCoding protocol like this

-initWithCoder: coder
{
int version = [coder versionForClassNamed:NSStringFromClass(MyClass)];

[super initWithCoder:coder];
if(version >= 1)
{
// decode feature
}
else
{
// init feature
}
return self;
}

Raphael

On Tuesday, October 2, 2001, at 09:21 AM, Alex Rice wrote:

-initWithCoder: coder
{
// in a class deep within the object graph &
// in a galaxy far far away
// document features added after document version 1.0
NS_DURING
// v1.1 feature:
[coder decodeValueOfObjCType:@encode(typeof(feature)) at:&(feature)];
NS_HANDLER
feature = MyDefault;
NSLog(@"failed to read feature");
[coder rollback]; //?
NS_ENDHANDLER
// now the next object in the graph can be safely initWithCoder'd
}


References: 
 >NSUnarchiver question (From: Alex Rice <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.