title: timestamp and calculating velocity of a swipe
body: <p>Hey I know there are already a few posts about this - yet I still can't find an adequate answer for the problem I'm having. </p>
  
  <p>Just new to cocoa and iOS, I'm in the middle of developing my first iOS game. In this game I would like to be able to calculate the speed of a user's swipe. I'm having no difficulty finding the distance between successive touches in the swipe motion, but am having difficulty determining the time elapsed between the touches</p>
  
  <ul>
  <li><p>in <code>touchesMoved:</code> I do calculations with the current touch as well as keep track of the last previously recorded touch as a UITouch</p></li>
  <li><p>in <code>touchesEnded:</code> I now want to calculate the speed of swipe, but when I do something like:</p>
  
  <p>double timeDelay = event.timestamp - self.previousTouch.timestamp;</p></li>
  </ul>
  
  <p>this always returns 0.</p>
  
  <p>However, using gcc I'm able to see that the two timestamps are in fact NOT the same. Additionally, upon inspecting I saw that the NSTimeInterval values for these events were on the magnitude of ~ 10^(-300). This seems odd as an NSTimeInterval is supposed to report seconds since system start up is it not?</p>
  
  <p>I've also tried keeping track of the NSDate of the previous touch and use it with conjunction with [NSDate timeIntervalSinceNow]. This yielded even stranger results, returning a value around 6 every time. Again, since timerIntervalSinceNow returns a <code>NSTimeInterval</code>, this value is very strange.</p>
  
  <p>What am I not understanding about timestamps? events?
  Any help on this would be greatly appreciated!
  Thanks for your time</p>
  
  <p>some supporting code:</p>
  
  <p>In sampleController.h:</p>
  
  <pre><code>@property(nonatomic) UITouch* previousTouch
  @property(nonatomic) UITouch* currentTouch
  </code></pre>
  
  <p>In sampleController.m:</p>
  
  <pre><code>@synthesize previousTouch = _previousTouch, currentTouch = _currentTouch;
  ...
  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
         self.currentTouch = [[event allTouches] anyObject];
         // do stuff with currentTouch
  }
  ...
  - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
         self.previousTouch = self.currentTouch;
         self.currentTouch = [[event allTouches] anyObject];
         // do stuff with currentTouch
  }
  ...
  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
         float distanceMoved = [self.touch locationInView:self.playView].x - 
                [self.touch previousLocationInView:self.playView].x;
         // attempt 1
         double timeElapsed = self.currentTouch.timestamp - self.previousTouch.timestamp;
  
         // attempt 2
         double timeElapsed = event.timestamp - self.previousTouch.timestamp;
  
         // do stuff with distanceMoved and timeDelay
  }
  </code></pre>