title: Difference between 2 dates in seconds ios
body: <p>I have an app where content is displayed to the user. I now want to find out how many seconds a user actually views that content for. So in my header file, I've declared an</p>
  
  <pre><code> NSDate *startTime;
   NSDate *endTime;
  </code></pre>
  
  <p>Then in my viewWillAppear</p>
  
  <pre><code> startTime = [NSDate date];
  </code></pre>
  
  <p>Then in my viewWillDisappear</p>
  
  <pre><code>endTime = [NSDate date];
  NSTimeInterval secs = [endTime timeIntervalSinceDate:startTime];
  NSLog(@"Seconds --------&gt; %f", secs);
  </code></pre>
  
  <p>However, the app crashes, with different errors sometimes. Sometimes it's a memory leak, sometimes it's a problem with the NSTimeInterval, and sometimes it crashes after going back to the content for a second time.</p>
  
  <p>Any ideas on to fix this?</p>