• 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: initWithCoder: calling init in custom class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: initWithCoder: calling init in custom class


  • Subject: Re: initWithCoder: calling init in custom class
  • From: Trygve Inda <email@hidden>
  • Date: Mon, 16 Jun 2014 15:24:57 -0700
  • Thread-topic: initWithCoder: calling init in custom class

> On Jun 16, 2014, at 13:36 , Trygve Inda <email@hidden> wrote:
>
>> In the later method, if the encoded object does not contain kValueCKey, the
>> object created will still have the correct default value for valueC (9).
>
> It won’t, because you assigned nil to valueC *after* it’s set to the default.
>
> Personally, I’d be inclined to have initWithCoder call super, because in more
> complicated examples the logic tends to be quite different. If you have common
> initialization (such as the initial setting of defaults), put them in a
> private method that both initializers call.
>

You're right. I wrote that right before nap time.  :-)

I guess the only way to prevent this is to check to see if

[coder decodeObjectForKey:kValueAKey]

returns non-nil before assigning it to valueA.

Trygve




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: initWithCoder: calling init in custom class
      • From: Scott Ribe <email@hidden>
References: 
 >Re: initWithCoder: calling init in custom class (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: initWithCoder: calling init in custom class
  • Next by Date: Re: initWithCoder: calling init in custom class
  • Previous by thread: Re: initWithCoder: calling init in custom class
  • Next by thread: Re: initWithCoder: calling init in custom class
  • Index(es):
    • Date
    • Thread