Measuring Time Accurately in Swift for Comparison Across Devices

后端 未结 3 2082
暗喜
暗喜 2020-12-09 14:17

I need to be able to record reaction time, from when the screen loads or the question label refreshes until the user taps a number button. I\'m not finding documentation fro

3条回答
  •  粉色の甜心
    2020-12-09 14:47

    NSDate is tied to the realtime clock on iOS and Mac devices, and has sub-millisecond accuracy.

    Use NSDate's timeIntervalSinceReferenceDate method to convert an NSDate (or the current time) to a double that is the number of seconds since January 1, 2001, including fractional seconds. Once you do that you're free to do math on the doubles that you get back.

提交回复
热议问题