Archiving, coding etc.
Archiving, coding etc.
- Subject: Archiving, coding etc.
- From: "Smith, Bradley" <email@hidden>
- Date: Tue, 9 Oct 2001 09:34:09 +0100
Hi everyone,
I'm having trouble loading my documents (and possibly saving them. Hard
to tell).
My document class implements loadDataRepresentation with code like this: -
m_theModel = [NSUnarchiver unarchiveObjectWithData: data];
m_theModel is an instance of CModel, which is a class which derives from
CItem and contains an NSMutableArray of CClass(es), which also derive
from CItem. CItem has one data member - NSString *m_strName;
CItem conforms to the NSCoding protocol and implements the following : -
- (id)initWithCoder:(NSCoder *)coder
{
[self setName: [coder decodeObject]];
return self;
}
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject: [self name]];
return;
}
CClass does not override anything.
CModel has this: -
- (id)initWithCoder:(NSCoder *)coder
{
// Let CItem decode the name
self = [super initWithCoder: coder];
// Decode our array of classes
[m_theClasses initWithCoder: coder];
return self;
}
- (void)encodeWithCoder:(NSCoder *)coder
{
// Encode the name
[super encodeWithCoder: coder];
// Encode our classes
[coder encodeObject: [self classes]];
return;
}
My document *seems* to save okay i.e. when I open it in BBEdit I see in
amongst the binary bits the names of my classes and the contents of the
m_strName strings and they seem to be in the order I would expect to have
encoded them.
When I open my document though I get the following error: -
2001-10-09 01:37:59.937 umlX[1273] *** NSUnarchiver: inconsistency
between written and read data for object 0x225b630
Anyone know what I'm doing wrong (probably loads of stuff)?
Brad