Your attempt to calculate elapsedTime is incorrect. In Swift 3, it would be:
let elapsed = Date().timeIntervalSince(timeAtPress)
Note the () after the Date reference, which calls Date.init.
Alternatively, nowadays (e.g., iOS 15+, macOS 12+), we might prefer to use now, which does precisely the same thing, but makes the functional intent explicit through its name:
let elapsed = Date.now.timeIntervalSince(timeAtPress)
The Date()/Date.init()/Date.now instantiates a new date object, and then timeIntervalSince returns the time difference between that and timeAtPress. That will return a floating point value (technically, a TimeInterval).
If you want that as truncated to a Int value, you can just use:
let duration = Int(elapsed)
There are a few alternatives:
- Nowadays (iOS 16+, macOS 13+), we might use a - Clock, e.g., a- ContinuousClockor a- SuspendingClock:
 - let clock = ContinuousClock()
let start = clock.now
// do something
let elapsed = .now - start
 - Or we can - measurethe amount of time something takes:
 - // for async routines
let elapsed = try await ContinuousClock().measure {
    // something asynchronous with `await`
}
// for synchronous routines
let elapsed = ContinuousClock().measure {
    // something synchronous
}
 - These clocks are introduced about 6 minutes into WWDC 2022 video Meet Swift Async Algorithms. 
- Sometimes, we just want the number of elapsed seconds, e.g., with - CFAbsoluteTimeGetCurrent():
 - let start = CFAbsoluteTimeGetCurrent()
// do something
let elapsed = CFAbsoluteTimeGetCurrent() - start
 
- It's worth noting that the - CFAbsoluteTimeGetCurrentdocumentation warns us:
 - 
- Repeated calls to this function do not guarantee monotonically increasing results. The system time may decrease due to synchronization with external time references or due to an explicit user change of the clock. 
 - This means that if you're unfortunate enough to measure elapsed time when one of these adjustments take place, you can end up with incorrect elapsed time calculation. This is true for - NSDate/- Datecalculations too. It's safest to use a- mach_absolute_timebased calculation (most easily done with- CACurrentMediaTime):
 - let start = CACurrentMediaTime()
// do something
let elapsed = CACurrentMediaTime() - start
 - This uses - mach_absolute_time, but avoids some of its complexities outlined in Technical Q&A QA1398.
 - Remember, though, that - CACurrentMediaTime/- mach_absolute_timewill be reset when the device is rebooted. So, bottom line, if you need accurate elapsed time calculations while an app is running, use- CACurrentMediaTime. But if you're going to save this start time in persistent storage which you might recall when the app is restarted at some future date, then you have to use- Dateor- CFAbsoluteTimeGetCurrent, and just live with any inaccuracies that may entail.