• 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: Newbie Q : Not-so-simple encoding&decoding example
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie Q : Not-so-simple encoding&decoding example


  • Subject: Re: Newbie Q : Not-so-simple encoding&decoding example
  • From: "Shawn Erickson" <email@hidden>
  • Date: Fri, 26 May 2006 17:28:00 -0700

On 5/26/06, Chris Suter <email@hidden> wrote:
>> In Class1.m
>>
>> -- (id)initWithCoder:(NSCoder *)coder
>> {
>>    if (self = [super init]) {
>>             [array1 release];
>>            [array2 release];
>
> These are pointless releases. You just called -[super init]. All of
> your instance variables are guaranteed to be nil. There is no point
> in sending release messages to object pointer you know are nil.

Out of interest what guarantees they're nil? I thought it was alloc
that guarantees your data is zeroed, not a call to init.

Yeah it is alloc... the ObjC runtime ensures that instance variables are zeroed when the object instance is allocated.

It is generally considered a bad Cocoa coding style to send init to an
already initialized object so you usually don't code your init methods
to check/adjust prior internal state of your object, you usually just
assume that you are dealing with a freshly initialized object
instance.

If you are concerned about reinit of an object instance I recommend
using asserts to detect and flag such attempts and not make attempts
in your init to allow for reinit.

Of course their are always exceptions to a "rule" such as this but...

-Shawn
_______________________________________________
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


  • Follow-Ups:
    • Re: Newbie Q : Not-so-simple encoding&decoding example
      • From: "Shawn Erickson" <email@hidden>
References: 
 >Re: Newbie Q : Not-so-simple encoding&decoding example (From: Chris Suter <email@hidden>)

  • Prev by Date: Re: Newbie Q : Not-so-simple encoding&decoding example
  • Next by Date: Re: Newbie Q : Not-so-simple encoding&decoding example
  • Previous by thread: Re: Newbie Q : Not-so-simple encoding&decoding example
  • Next by thread: Re: Newbie Q : Not-so-simple encoding&decoding example
  • Index(es):
    • Date
    • Thread