I need to be able to record the reaction time, starting from the moment the screen or question mark is loaded, until the user presses a number button. I do not find Apple's documentation about this to be very useful. NSDatenot accurate enough, I need to at least measure milliseconds. mach_absolute_timegame designers seem to prefer because it is internally consistent, but it won’t work for this application because I need to compare data between devices, and mach_absolute_timeit’s processor- specific time. This Apple Dev Q & A suggests using NanosecondsToAbsoluteand DurationToAbsolute, but it is in obj-c, and I cannot find a quick equivalent documentation.
Is there a quick version NanosecondsToAbsoluteand DurationToAbsoluteone that I just can't find? Another way to do this sequentially?
Here is the code I'm trying to add:
class EmotionQuestionsViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
}
@IBOutlet var questionLabel: UILabel!
var timeResultsStack = [String]()
var questionsStack = ["HAPPY", "ANXIOUS"]
var questionResultsStack = [String]()
var questionStackArrayIndex = 1
@IBAction func RecordValueFromNumericalScaleOneToSeven(sender: UIButton) {
let value = sender.currentTitle!
questionResultsStack.append(value)
if questionResultsStack.count < questionsStack.count{
self.questionLabel.text = "how \(questionsStack[questionStackArrayIndex]) are you right now?"
self.questionStackArrayIndex++
}
else{
self.performSegueWithIdentifier("showResults", sender: nil)
}
}
source
share