[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NSUnarchiver extensions
From: |
Richard Frith-Macdonald |
Subject: |
Re: NSUnarchiver extensions |
Date: |
Tue, 26 Feb 2002 12:54:14 +0000 |
On Tuesday, February 26, 2002, at 12:34 PM, Pierre-Yves Rivaille wrote:
Unless I'm missing something, I think the change is pointless (and
therefore
bloat).
It seems to me that if you are substituting one class for another when
decoding, the replacement class
*must* know all about the class it is replacing.
The problem is that the initWithCoder is used to decode GSCustomView
object *and* GormCustomView object too.
And there is no easy way to know if I'm decoding a GSCustomView or a
GormCustomView, so I don't know if I should call [aCoder
versionForClassName: @"GSCustomView"] or [aCoder versionForClassName:
@"GormCustomView"].
Calling the wrong [aCoder versionForClassName: @"..."] leads to a
segfault.
should return NSNotFound ... fixed in CVS.
I'm confused as to why you should ever be decoding a GormCustomView. As
far as I know, it gets encoded into
archives as a GSCustomView, so you should always see a GSCustomView in
the archive rather than a GormCustomView.
However, given that for some reason you have managed to get an archive
that contains both classes, the decoding class
needs to know which class it is replacing, just knowing a version is not
enough.
Another way to do thing would be to patch the [NSUnarchiver
versionForClassName:] methods so that it returns a specific value when
the class does not exist in the archive (maybe NSNotFound, but it may
interact with some class's version, although it is unlikely), or maybe
raise an exception. (I've implemented the first solution at some point
but I dumped it for some reason I forgot ..., but i've never played
with exceptions in objc).
Should return NSNotFound ... fixed. However, this is not actually
relevant to your problem.
(The dirty trick solution would be to turn on and off a class variable
for GormCustomView before and after loading a nib file, so that it
knows when it is used to decode a GSCustomView or a GormCustomView.)
That's quick and effective - I wouldn't call it nearly as dirty as
changing the
NSArchiver/NSUnarchiver API, since it's at least local to the one class
needing it.
Alternatively, how about ...
if ([[aCoder classNameDecodedForArchiveClassName: @"GSCustomView"]
isEqual: @"GormCustomView"])
{
// decode a GSCustomView
}
else
{
// decode a GormCustomView
}