title: Custom UIViewController init with init related data
body: <p>I have a question regarding the custom <code>init</code> methods specifically on <code>UIViewControllers</code>. Let's say that I write an <code>init</code> method which takes one parameter (let's say <code>UIViewControllerInitMode</code>) and that parameter is responsible to indicate in which way the view should load. So when the <code>viewDidLoad</code> gets called that parameter (now stored as a class variable) gets checked and the GUI related content is loaded accordingly. How is this done?</p>
  
  <p>Let's take this example:</p>
  
  <p>We have a <code>NS_ENUM</code> called <code>UIViewControllerInitMode</code> with modes <code>kUIViewControllerInitModeOne</code> and <code>kUIViewControllerInitModeTwo</code>. Now for the <code>init</code> and <code>viewDidLoad</code> code:</p>
  
  <pre><code>- (instancetype)initWithMode:(UIViewControllerInitMode)m
  {
      self = [super init];
      if (self)
      {
           mode = m; //Assume that mode is a class variable
      }
      return self;
  }
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  
      if (mode == kUIViewControllerInitModeOne) //Check the class variable
          self.view.backgroundColor = [UIColor blueColor];
      else //It's the InitModeTwo
          self.view.backgroundColor = [UIColor redColor];
  }
  </code></pre>
  
  <p>Now this looks like a perfectly legitimate piece of code (at least to me) but if my knowledge is correct the actual view of a <code>UIViewController</code> gets lazy loaded so there is no telling if the view is blue or red when the class variable gets set (except with an extra if but that looks ugly because it would mean I have the same code for GUI in <code>init</code> and in <code>viewDidLoad</code>). So does this mean that under some circumstances the view can have a red background even if I <code>init</code>ed the controller with the mode that should make a blue background? Setting the background color in <code>init</code> is not safe for the same reason or is it? It always works if I do it in the way of the example above but I want to get to the bottom of this. How does this happen under the hood? Where am I right and/or wrong?</p>