title: Objective-C invalidate timer in another method
body: <p>I have a method in which i have declared a timer;</p>
  
  <pre><code>- (void)startTimer:(id)sender {
      NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval: 0.8
                                                       target: self
                                                     selector: @selector(toggleButtonImage:)
                                                     userInfo: nil
                                                      repeats: YES];  
  }
  </code></pre>
  
  <p>What i want to do is, in another method i want to invalidate the timer if it is running, here's the what i have so far but i get the error 'timer is undeclared'</p>
  
  <pre><code>- (void)stopTimer:(id)sender {
      if ( [timer isValid]) {
        [timer invalidate], timer=nil;
      }
  }
  </code></pre>
  
  <p>Could anyone help me?</p>