How do I repeat this function continuously instead of invalidating it? I've marked out the else section at the bottom of the code and it currently just keeps displaying one title and not repeating the whole function.
func handleTimer(_ timer: Timer) {
if let currentPhase = self.phasesInProgress.last, let timerStart = timerStart {
debugPrint("Current Phase: \(currentPhase.title)")
let currentPhaseEndTime = TimeInterval(currentPhase.endTime)
let elapsedTime = abs(timerStart.timeIntervalSinceNow)
debugPrint("Elapsed Time: \(elapsedTime)")
if elapsedTime > currentPhaseEndTime {
debugPrint("Phase over current > \(currentPhaseEndTime), going to next.")
self.phasesInProgress.removeLast()
handleTimer(timer)
} else {
let phaseElapsed = elapsedTime - currentPhase.startTime
let duration = currentPhase.endTime - currentPhase.startTime
phaseTimeElapsedChanged(phaseElapsed, duration)
phaseChanged(currentPhase.title)
}
// } else {
// self.timer?.invalidate()
// self.completion()
}
Aucun commentaire:
Enregistrer un commentaire