• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Solved [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >[Q] Why unsolicited dealloc in NSKeyedUnarchiver? (From: "Peter.Teeson" <email@hidden>)
 >Re: [Q] Why unsolicited dealloc in NSKeyedUnarchiver? (From: "Louis C. Sacha" <email@hidden>)
 >Re: [Q] Why unsolicited dealloc in NSKeyedUnarchiver? (From: "Peter.Teeson" <email@hidden>)
 >Re: [Q] Why unsolicited dealloc in NSKeyedUnarchiver? (From: Shawn Erickson <email@hidden>)
 >Re: Solved [Q] Why unsolicited dealloc in NSKeyedUnarchiver? (From: "Peter.Teeson" <email@hidden>)
 >Re: Solved [Q] Why unsolicited dealloc in NSKeyedUnarchiver? (From: John Randolph <email@hidden>)

  • Prev by Date: Failed Dictionary Search yields Signal 10 (SIGBUS) when all I want is a nil. (*** Solved ***)
  • Next by Date: Re: Grabing Disk Information
  • Previous by thread: Re: Solved [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
  • Next by thread: Re: [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
  • Index(es):
    • Date
    • Thread