My code returns the error: fatal error: floating point value can not be converted to UInt8 because it is greater than UInt8.max. The code is being called when a button is pressed (in a different swift file) but I know that the problem wasn't with calling the function so I didn't include it.
code:
//starts the timer
func startTimer(sender: AnyObject)
{
if !timer.valid
{
timer = NSTimer.scheduledTimerWithTimeInterval(0.01, target: sender, selector: Selector(updateTime()), userInfo: nil, repeats: true)
startTime = NSDate.timeIntervalSinceReferenceDate()
//disp = timerDisplay
}
}
//function that configures the timer
func updateTime()
{
var currentTime = NSDate.timeIntervalSinceReferenceDate()
//find the difference between the current time and the start time
var elapsedTime: NSTimeInterval = currentTime - startTime
//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 * 10)
//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)
//display the time left to a string
timerDisplay = "\(strSeconds):\(strFraction)"
}
func stopTimer()
{
timer.invalidate()
}