Re: Application failing on copyWithZone:
Re: Application failing on copyWithZone:
- Subject: Re: Application failing on copyWithZone:
- From: Andrew Merenbach <email@hidden>
- Date: Sun, 18 Jun 2006 15:23:42 -0700
(Already sent to Kevin, but I forgot to CC.)
Hi, Kevin. Sorry if this is a stupid question (and it probably is),
but have you implemented -copyWithZone: in your AccountDocument
class? You'll need it for NSCoding to work properly with it, since
it's not a class that's serializable by default. Once again, I'm
probably preaching to the choir, so forgive me if I am, but basically
just create a copy of your object and set its attributes to be the
same as the original's, then return the copy (NOT autoreleased).
Again, sorry if I'm speaking to someone who has tried this, but you
did not mention it anywhere so I thought that I would.
Best wishes,
Andrew
On Jun 18, 2006, at 3:07 PM, Kevin Hoctor wrote:
I had a working application until I tried to take the NSCoding
process to the next level. It worked fine when my application
simply coded and decoded an NSMutableArray (called accounts) as a
member of my DQDocument class, but now it fails with this error:
2006-06-18 11:46:59.799 Debt Quencher[13979] *** -[AccountDocument
copyWithZone:]: selector not recognized [self = 0x33e7c0]
The change I made was to add a higher level class called
AccountDocument:
@implementation AccountDocument
- (id)initWithCoder:(NSCoder *)coder
{
[super init];
[self setCurrentMethodInUse:[coder
decodeIntForKey:@"currentMethodInUse"]];
[self setAccounts:[coder decodeObjectForKey:@"accounts"]];
[self setPrintInfo:[coder decodeObjectForKey:@"printInfo"]];
return self;
}
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeInt:currentMethodInUse forKey:@"currentMethodInUse"];
[coder encodeObject:accounts forKey:@"accounts"];
[coder encodeObject:printInfo forKey:@"printInfo"];
}
I used to just have accounts in my NSDocument subclass and I
replaced it with accountDocument. Now I get the above error when I
try to open a new document. I'm concerned that I'm chasing a ghost
and this has nothing to do with the NSCoding but rather something
in my nib. I have an NSArrayController managing accounts.
@implementation DQDocument
- (NSMutableArray *)accounts
{
return [[self accountDocument] accounts];
}
- (void)setAccounts:(NSMutableArray *)array
{
[self setAccounts:array];
}
@end
Anything here that helps pinpoint my mistake? I've read (and
reread) all the guides and documentation and my Cocoa books but I'm
stumped.
Thanks,
Kevin Hoctor
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40ucla.edu
This email sent to email@hidden
_______________________________________________
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