According to the NSObject UIKit Additions Reference, outlet variables should be set by the time awakeFromNib is called (emphasis all mine):

The nib-loading infrastructure sends an awakeFromNib message to each object recreated from a nib archive, but only after all the objects in the archive have been loaded and initialized. When an object receives an awakeFromNib message, it is guaranteed to have all its outlet and action connections already established.

...

Important: Because the order in which objects are instantiated from an archive is not guaranteed, your initialization methods should not send messages to other objects in the hierarchy. Messages to other objects can be sent safely from within an awakeFromNib method.

Typically, you implement awakeFromNib for objects that require additional set up that cannot be done at design time. For example, you might use this method to customize the default configuration of any controls to match user preferences or the values in other controls. You might also use it to restore individual controls to some previous state of your application.

However, this does not match my tests, at least using Storyboards. The results of the following test seem to contradict the documentation:

  • Create a new Single View Application in Xcode.
  • Drag a second ViewController onto the storyboard.
  • Give the first ViewController a button, and create a modal segue from that button that displays the second ViewController.
  • Create a ViewController class file for the second ViewController.
  • Create a label on the second ViewController on the storyboard and create an outlet called someLabel from it to the corresponding ViewController clas
Edit
Report