I have made a timer in xcode for an app, and I'm trying to average the times but in order to do that, I need to save the output string from NSTimer to a variable. I formatted it to have three strings that read as one, which looks like "00:00:00" with minutes, seconds, and milliseconds. How can I save the individual chunks as variables? I know how to use the substrings to isolate the pieces, I just need to save them as variables.
func updateTime() {
var currentTime = NSDate.timeIntervalSinceReferenceDate()
//Find the difference between current time and start time.
var elapsedTime: NSTimeInterval = currentTime - startTime
//calculate the minutes in elapsed time.
let minutes = UInt8(elapsedTime / 60.0)
elapsedTime -= (NSTimeInterval(minutes) * 60)
//calculate the seconds in elapsed time.
let seconds = UInt8(elapsedTime)
elapsedTime -= NSTimeInterval(seconds)
//find out the fraction of milliseconds to be displayed.
let fraction = UInt8(elapsedTime * 100)
//add the leading zero for minutes, seconds and millseconds and store them as string constants
let strMinutes = minutes > 9 ? String(minutes):"0" + String(minutes)
let strSeconds = seconds > 9 ? String(seconds):"0" + String(seconds)
let strFraction = fraction > 9 ? String(fraction):"0" + String(fraction)
//concatenate minuets, seconds and milliseconds as assign it to the UILabel
timerLabel.text = "\(strMinutes):\(strSeconds):\(strFraction)"
}
There's where I updated the time, not exactly sure what else you need to see.