Re: Solved [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
Re: Solved [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
- Subject: Re: Solved [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
- From: "Peter.Teeson" <email@hidden>
- Date: Wed, 28 Apr 2004 18:59:12 -0400
On Apr 27, 2004, at 17:46, John Randolph wrote:
>
What you've got above will work, but you have two unnecessary lines of
>
code there. There's no need to create and then release an array for
>
passwordRecs, since you're going to get one from -decodeObjectForKey:.
>
>
Try:
>
>
-(id)initWithCoder:(NSCoder *)coder {
>
self = [super init];
>
[self addPasswordRecord];
>
if ([coder allowsKeyedCoding]) {
>
passwordRecs = [coder decodeObjectForKey:@"passwordRecs"];
>
[passwordRecs retain]; // retain auto-released object
>
}
>
return self;
>
}
Thank you for your patient advice.
I ended up making an accessor method
The final code looks like this which is probably more correct.
- (void)setPasswordRecs:(NSMutableArray *)newPasswordRecs {
[newPasswordRecs retain];
[passwordRecs release];
passwordRecs = newPasswordRecs;
}
-(id)initWithCoder:(NSCoder *)coder {
self = [super init];
[self setPasswordRecs:[NSMutableArray array]];
[self addPasswordRecord];
if ([coder allowsKeyedCoding]) {
[self setPasswordRecs:[coder decodeObjectForKey:@"passwordRecs"]];
}
return self;
}
_______________________________________________
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.