title: NSTimer Troubles
body: <p>I am trying to run the code below but it keeps locking up my simulator after the "Tick" is written to the console. It never outputs "Tock" so my guess is that it has to do with the line "NSTimeInterval elapsedTime = [startTime timeIntervalSinceNow];" The IBactions are activated by buttons. timer and startTime are defined in the .h as NSTimer and NSDate respectively.</p>
  
  <p>Can anyone tell me what I am doing wrong? </p>
  
  <p>code:</p>
  
  <pre><code>- (IBAction)startStopwatch:(id)sender
  {
      startTime = [NSDate date];
      NSLog(@"%@", startTime);
      timer = [NSTimer scheduledTimerWithTimeInterval:1 //0.02
                                               target:self
                                             selector:@selector(tick:)
                                             userInfo:nil
                                              repeats:YES];
  }
  
  - (IBAction)stopStopwatch:(id)sender
  {
      [timer invalidate];
      timer = nil;
  }
  
  - (void)tick:(NSTimer *)theTimer
  {
      NSLog(@"Tick!");
      NSTimeInterval elapsedTime = [startTime timeIntervalSinceNow];
      NSLog(@"Tock!");
      NSLog(@"Delta: %d", elapsedTime);
  }
  </code></pre>
  
  <p>I have the following in the .h:</p>
  
  <pre><code>@interface MainViewController : UIViewController &lt;FlipsideViewControllerDelegate&gt; {
  
      NSTimer *timer;
      NSDate *startTime;
  }
  
  
  - (IBAction)startStopwatch:(id)sender;
  - (IBAction)stopStopwatch:(id)sender;
  - (void)tick:(NSTimer *)theTimer;
  
  @property(nonatomic, retain) NSTimer *timer;
  @property(nonatomic, retain) NSDate *startTime;
  
  @end
  </code></pre>