Odd problem using NSCoding
Odd problem using NSCoding
- Subject: Odd problem using NSCoding
- From: <email@hidden>
- Date: Wed, 6 Apr 2005 7:37:17 +0000
Hey there. I have a simple doc-based app that manages a single model object. The model object implements NSCoding and also overrides initWithCoder and encodeWithCoder. I then use an NSKeyedArchiver in MyDocument to archive the object to disk (archiveDataWithRootObject) in dataRepresentationOfType. Also use an NSKeyedUnarchiver to unarchive the model object back (unarchiveObjectWithData) in loadDataRepresentation:ofType:.
My interface elements are properly bound to my model object instance variables. But when I try to "open" a file that I previously saved, I get the following from the Log window twice:
[TradeModel copyWithZone:]: selector not recognized [self = 0x3ee2e0]
Now, two of my model instances are int primitives, and I was encoding and decoding using NSNumber class methods, like so:
- (void)encodeWithCoder:(NSCoder*)coder
{
[coder encodeObject:[NSNumber numberWithInt:[self tradeTypeValue]]];
[coder encodeObject:[NSNumber numberWithInt:[self tradeStatusValue]]];
[coder encodeObject:[self traderName]]; // NSString var
[coder encodeObject:[self traderAddress]]; // NSString var
}
(id)initWithCoder:(NSCoder*)coder
{
[super init];
[self setTradeTypeValue:[[coder decodeObject] intValue]];
[self setTradeStatusValue:[[coder decodeObject] intValue]];
[self setTraderName:[coder decodeObject]];
[self setTraderAddress:[coder decodeObject]];
return self;
}
I send intValue to the decoded object because I encoded it as an NSNumber. Thinking that something was going hinky with the NSNumber conversion, I commented out both lines in both methods, so I would only encode/decode the two other NSString variables. Got the same error message.
The thing is, I also have another small app I wrote quite some time ago that does the exact same thing I'm doing now to a T. Doc-based app, one model object, one NSObjectController and interface elements bound to model ivars. The code for the two model objects are virtually identical except for the variable names. It works fine, but for some reason, this new app isn't working at all when initWithCoder: is executed. So I set a breakpoint. It chokes on the call to [super init], which is the first line of initWithCoder. It does this whether or not I override init:.
Any thoughts? Thanks in advance. Sorry for the length, wanted to make sure I included enough relevant info.
James
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden