views:

26

answers:

1

I'm trying to measure time between taps. I've gathered code from a couple other posts, but still no luck. I running into issues when I'm taking the difference between two time stamps and trying to make it readable in seconds.

    // Time elapsed
NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:touchesBegan];

NSDateFormatter *formatted = [[NSDateFormatter alloc] init];
[formatted setDateFormat: @"ss"];

NSString *stringFromDate = [ formatted stringFromDate:duration];

The error comes on the last line where the formatting is supposed to occur: Error: Incompatible type for argument 1 of 'stringFromDate'

Thanks

+2  A: 

The stringFromDate: method of NSDateFormatter takes an NSDate as its argument. You are passing it an NSTimeInterval. NSTimeInterval is a double, containing a duration in seconds. So, you can get rid of the NSDateFormatter and simply generate a string using the duration like a double:

NSString *stringFromInterval = [NSString stringWithFormat:@"%g", duration];
James Huddleston