Re: Archiving problem with subclass of NSCalendarDate
Re: Archiving problem with subclass of NSCalendarDate
- Subject: Re: Archiving problem with subclass of NSCalendarDate
- From: Chris Kane <email@hidden>
- Date: Sat, 23 Feb 2002 16:19:26 -0800
Because NSDate is a class cluster, it has a -classForCoder method that
hides private subclasses by specifying that unarchived dates should be
unarchived as NSDate instances (the NSDate class will then substitute an
appropriate instance of a subclass at unarchiving time):
- (Class)classForCoder {
return [NSDate self];
}
NSCalendarDate, since it is a public concrete subclass of NSDate, needs
to override this so that the "calendar date-ness" is not lost, and it
does this by:
- (Class)classForCoder {
return [NSCalendarDate self];
}
Arguably this should be:
- (Class)classForCoder {
return [self class];
}
So that subclasses of NSCalendarDate, which themselves are concrete,
don't have to override this method as well. But it isn't that way.
If you add:
- (Class)classForCoder {
return [self class];
}
to LunarDate's implementation, things will work.
Chris Kane
Cocoa Frameworks, Apple
On Tuesday, January 22, 2002, at 08:50 AM, email@hidden wrote:
hello,
I'm trying to make lunar calendar.
So, I made LunarDate class, subclass of NSCalendarDate. and added some
instance variables, methods...for lunar.
everything works fine except Archiving and Unarchiving. I tried and
tried to solve this problem, but couldn't.
How can I Archive subclass of NSCalendarDate?
this is my sample code for archiving..
@interface LunarDate : NSCalendarDate <NSCoding>{
NSString *str;
BOOL isLeap;
.
.
}
@implementation LunarDate
-(id)initWithCoder:(NSCoder*)coder
{
if(self=[super initWithCoder:coder])
{
[self setStr:[coder decodeObject]];
}
return self;
}
-(void)encodeWithCoder:(NSCoder*)coder
{
[super encodeWithCoder:coder];
[coder encodeObject:str];
}
when I subclass NSObject,(After deleting if(self=....),[super ....])
,this code works fine..but whenever I subclass NSCalendarDate , and
Unarchive it,
*** NSUnarchiver: inconsistency between written and read data for
object 0x1433f0 Error occured.
how can I Archive the subclass of NSCalendarDate?..
and..sorry poor my English :-<
_______________________________________________
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.
_______________________________________________
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.