title: Dynamic type of view controller
body: <p>I have some repetitive code I'm trying to refactor:</p>
  
  <pre><code>if (_currentIndex &gt;= [_questions count] - 1) {
      [patient setDate:[NSDate date]];
      ConfirmationViewController *confirmation = [self.storyboard instantiateViewControllerWithIdentifier:@"Confirmation"];
      [confirmation setPatient:patient];
      [confirmation setQuestions: _questions];
      [self.navigationController pushViewController:confirmation animated:YES];
  
  } else if ([[_questions objectAtIndex:_currentIndex + 1] isEqualToString:@"date"]) {
      DateViewController *dateView = [self.storyboard instantiateViewControllerWithIdentifier:@"Date"];
      [dateView setPatient:patient];
      [dateView setQuestions: _questions];
      [dateView setCurrentIndex: _currentIndex + 1];
      [self.navigationController pushViewController:dateView animated:YES];
  } else {
      QuestionViewController *nextQuestion = [self.storyboard instantiateViewControllerWithIdentifier:@"Question"];
      [nextQuestion setCurrentIndex:_currentIndex + 1];
      [nextQuestion setPatient:patient];
      [nextQuestion setQuestions: _questions];
      [self.navigationController pushViewController:nextQuestion animated:YES];
  }
  </code></pre>
  
  <p>I'd like to declare a variable <code>nextView</code> that can either be a ConfirmationViewController, DateViewController, or QuestionViewController, since all of these have the steps <code>setPatient:patient</code>, <code>[self.navigationController pushViewController...]</code> and <code>[setQuestions:_questions]</code>, and just call that block after the case-specific pieces of code are run, but since they are all different types I can't figure out how I would declare this 'view' variable (I have mostly JS background so I'm used to <code>var</code>-ing at the top!)</p>