Getting time elapsed in Objective-C

Ilya Suzdalnitski picture Ilya Suzdalnitski · Apr 12, 2009 · Viewed 116.7k times · Source

I need to get the time elapsed between two events, for example, the appearance of a UIView and the user's first reaction.

How can I achieve it in Objective-C?

Answer

Can Berk Güder picture Can Berk Güder · Apr 12, 2009
NSDate *start = [NSDate date];
// do stuff...
NSTimeInterval timeInterval = [start timeIntervalSinceNow];

timeInterval is the difference between start and now, in seconds, with sub-millisecond precision.