Skip navigation.
 
mlRe: initWithCoder in Nib object loading
FROM : Jonathan Hess
DATE : Fri Jun 27 19:30:09 2008

Hey John -

If you're thinking about overriding initWithCoder: just to do post NIB 
loading instantiation, I would recommend overriding awakeFromNib 
instead. The objects in the NIB are sent the initWithCoder: message 
because they're actually being decoded from an archive. Conceptually 
initWithCoder: should be used to implement the NSCoding protocol, and 
it should be paired with encodeWithCoder:. If you're custom view/
object isn't actually going to implement the NSCoding protocol, I 
think you should override awakeFromNib instead. The reason some 
obejcts get init, and some get initWithFrame: and others get 
initWithCoder: is that objects like the 'blue cube' in IB, or the 
'custom view' are typically placeholders for classes from your project 
that aren't available in IB, and might not implement NSCoding. So, 
after 'blue cube' or 'custom view' objects are unarchived, with 
initWithCoder:, they replace themselves with objects of the classes 
you specified in IB. The create those instances with an alloc message 
followed by either an init or initWithFrame:.

Good Luck -
Jon Hess

On Jun 27, 2008, at 4:28 AM, John Murphy wrote:

> I notice that there are a couple different init methods used for nib 
> loading. For instance, objects from the IB Library get an 
> initWithCoder message, while custom view objects get an 
> initWithFrame, and everything else gets an init. Why is this? 
> Specifically, why a special initWithCoder technique? After all, 
> isn't everything encoded?
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>

Related mailsAuthorDate
mlinitWithCoder in Nib object loading John Murphy Jun 27, 13:28
mlRe: initWithCoder in Nib object loading Michael Watson Jun 27, 14:27
mlRe: initWithCoder in Nib object loading Jonathan Hess Jun 27, 19:30