One Quickie


Decoding one class as another (NSCoder->General)
If you change the name of a class, and then try to use NSUnarchiver to expand an archived stream, you'll get an error like this (in this case "BWRawPath" was renamed to "BWSymbol"):

StitchEdit[3522] *** class error for 'BWRawPath': class not loaded

In a convenient place (like in the +load method of your class), use NSUnarchiver's decodeClassName:asClassName:

@implementation BWSymbol

+ (void) load
{
    [NSUnarchiver decodeClassName: @"BWRawPath"
                  asClassName: @"BWSymbol"];
 
    // No need to [super load] - the superclass +load has already
    // been invoked automatically by the runtime.

} // load
Note that this won't help you if you're wanting to rename something that was added via encodeValueOfObjCType:. You'll have to write some code to unarchive your data using the old @encode(oldName) and then re-archive it as @encode(newName)

(Thanks to Greg Miller for spotting an error in this quickie)



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com