PDA

View Full Version : Objective C Constructor




satyam90
Oct 26, 2007, 12:28 AM
What is the difference between init, initialize and awakeFromNib functions. All all are similar to constructors.



robbieduncan
Oct 26, 2007, 12:47 AM
You seem to have forgotten the + and - signs in front of the methods names:

+initialize initialises a Class (not an instance)

-init initialises and instance

-awakeFromNib initialises a de-serialised instance being created from a nib.

The last two are different as in the latter you can be sure any outlets connected in the nib are connects but this is not true in the former.

satyam90
Oct 26, 2007, 05:24 AM
I didn't understand what do u mean by "you can be sure any outlets connected in the nib are connects" in your response

robbieduncan
Oct 26, 2007, 06:45 AM
I didn't understand what do u mean by "you can be sure any outlets connected in the nib are connects" in your response

Exactly what I said. If you create an instance of this object in nib file then any outlets will not be connected when init gets called but will be when awakeFromNib is called.

kainjow
Oct 26, 2007, 07:33 AM
To better understand awakeFromNib you may want to read The Nib Object Life Cycle (http://developer.apple.com/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/chapter_3_section_3.html).