initWithCoder in Nib object loading

2008-06-27 Thread John Murphy
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 (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: initWithCoder in Nib object loading

2008-06-27 Thread Michael Watson
http://developer.apple.com/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/chapter_3_section_3.html 



All view objects are sent -initWithCoder:, but the custom view  
object does something extra. After the custom view object is  
unarchived, it creates your view subclass, sends the object an - 
initWithFrame: message, and then swaps itself for the subclass.



--
m-s

On 27 Jun, 2008, at 07:28, 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 (Cocoa-dev@lists.apple.com)

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/mikey-san 
%40bungie.org


This email sent to [EMAIL PROTECTED]


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: initWithCoder in Nib object loading

2008-06-27 Thread Jonathan Hess

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 (Cocoa-dev@lists.apple.com)

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/jhess%40apple.com

This email sent to [EMAIL PROTECTED]


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]