title: UIViewController: Use of undeclared identifier
body: <p>I have a method which looks like this:</p>
  
  <pre><code>- (void)testMethod:(int)myNumber {
      switch (myNumber) {
          case 0: {
              MyViewController0 *controller = [self.myViewControllers objectAtIndex:myNumber];
              if ((NSNull *)controller == [NSNull null]) {
                  controller = [[MyViewController0 alloc] initWithNibName:@"MyView0" bundle:nil];
                  controller.aVariable = self.myVariable;
                  [self.myViewControllers replaceObjectAtIndex:myNumber withObject:controller];
                  [controller release];
              }
              if (controller.view.superview == nil) {
                  // do some stuff with controller ...
              }
              break;
          }
          case 1: {
              MyViewController1 *controller = [self.myViewControllers objectAtIndex:myNumber];
              if ((NSNull *)controller == [NSNull null]) {
                  controller = [[MyViewController1 alloc] initWithNibName:@"MyView1" bundle:nil];
                  [self.myViewControllers replaceObjectAtIndex:myNumber withObject:controller];
                  [controller release];
              }
              if (controller.view.superview == nil) {
                  // do some stuff with controller ...
              }
              break;
          }
          // ...
      }
  }
  </code></pre>
  
  <p>My problem involves these lines, which are always the same:</p>
  
  <pre><code>if (controller.view.superview == nil) {
      // do some stuff with controller ...
  }
  </code></pre>
  
  <p>So, I want to remove these lines inside the switch-case and put them at the end of the method.</p>
  
  <p>The problem is, if I do this, I get the error: <code>Use of undeclared identifier controller</code>.
  I think it is because it is possible that the <code>controller</code> could remain undeclared (if no case is successful).</p>
  
  <p>But what can I do to avoid putting these lines in every case statement, can I instead put it once at the end of the method?</p>