Re: initWithCoder: calling init in custom class
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