RE: A String of Problems
RE: A String of Problems
- Subject: RE: A String of Problems
- From: "Jam Chen" <email@hidden>
- Date: Sun, 11 Jul 2004 16:45:56 +0800
- Thread-topic: A String of Problems
Hi,
Did you override the -setString since you have your own storage for
string?
And you forget to call super's init or initWithCoder in you
implementation
- (id)initWithCoder:(NSCoder *)coder
{
if (self = [super init]) {
[self setString: [coder decodeObjectForKey: @"string"]];
}
return self;
}
BTW, you should not retain the decode string before pass it to setString.
Just do
[self setString:[coder decodeObjectForKey: @"string"]];
Cause setString should take care of it.
HTH,
James
-----Original Message-----
From: email@hidden on behalf of Herr Witten
Sent: Sun 7/11/2004 2:53 PM
To: CocoaDev List
Subject: A String of Problems
I have a subclass of NSString that does not work correctly with
archiving; the subclass is the embedded type--where the data is held by
a normal NSString instance variable--and my NSCoding implementation
looks like this:
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject: _string forKey: @"string"];
}
- (id)initWithCoder:(NSCoder *)coder
{
[self setString: [[coder decodeObjectForKey: @"string"] retain]];
return self;
}
Yet they don't seem to be called at all.
Also, my subclass is archived properly the first time. Then, when it is
unarchived, it is allocated as an NSCFString so that it is archived
again incorrectly and so that the program crashes when it is used as
the subclass.
Any help would be appreciated.
Herr Witten
_______________________________________________
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.