title: Custom init of UIViewController from storyboard
body: <p>I tried finding some relevant questions but couldn't get anything, hope someone can help.</p>
  
  <p>I set up some UIViewController's on a storyboard. I then want to load one of the view controllers in code and push it onto the navigation stack. I figure out the right way to do this is to use </p>
  
  <p><code>instantiateViewControllerWithIdentifier</code></p>
  
  <p>This calls <code>init(coder: NSCoder)</code> and all is well, my program works, but I want to be able to have a custom initializer that sets up some variables for my view controller. Consider the following:</p>
  
  <pre><code>class A : UIViewController {   
  
    let i : Int
  
    required init(coder aDecoder: NSCoder) {
      super.init(coder: aDecoder)
      // property self.i not initialized at super.init call   
    }
  
  }
  </code></pre>
  
  <p>I obviously get an error since <code>i</code> needs to be specified at time of object creation. Any solutions to this? I am not interested in declaring <code>i</code> as <code>var</code> and configuring it later as that defeats the point and I no longer have a compiler guarantee that <code>i</code> is immutable.</p>
  
  <h2>Clarification edit</h2>
  
  <p>Suppose I have a currently loaded <code>ViewController</code> that has some variable <code>i</code>. This value is variable and can change. Now suppose from this ViewController I want to present another one, and initialize it with <code>i</code>.</p>
  
  <pre><code>class ViewController: UIViewController {
  
     var i : Int
  
     // ... other things
  
    // in response to some button tap...
    @IBAction func tappedButton(sender: AnyObject) {
      let st = UIStoryboard(name: "Main", bundle: nil)
      let vc = st.instantiateViewControllerWithIdentifier("AControllerID") as! A
      // How do I initialize A with i ?
      self.presentViewController(vc, animated: true, completion: nil)
    }
  
  }
  </code></pre>
  
  <p>I don't seem to be able to do this and keep <code>i</code> immutable by using <code>let</code> instead of <code>var</code>.</p>