I have the need to convert a string to Int so I can use an if > statement so I can enable and disable buttons. As you can see from the commented lines in the updateStopwatch I've tried a number of ways to convert but without any success
My Class looks like
class Stopwatch {
var startTime:Date?
func startTimer() {
startTime = Date();
}
func elapsedTimeSinceStart() -> String {
var elapsed = 0.0;
if let elapsedTime = startTime {
if firstHalfTime {
elapsed = elapsedTime.timeIntervalSinceNow
} else {
elapsed = elapsedTime.timeIntervalSinceNow - 45*60
}
}
elapsed = -elapsed
let minutes = Int(floor((elapsed / 60)));
let seconds = Int(floor((elapsed.truncatingRemainder(dividingBy: 60))));
// print(elapsed)
let timeString = String(format: "%02d:%02d", minutes, seconds)
// print(timeString)
return timeString
}
}
My update timer function
func updateStopwatch() {
let stopWatchString = stopWatch.elapsedTimeSinceStart()
stopwatchLabel.text = stopWatchString
// let minutesString:Int = Int(stopWatchString)!
// minutes = minutesString
if minutes > 1 {
endFirstHalf.isEnabled = true
self.endFirstHalf.alpha = 1
}
}