I have a working 10 minute countdown timer that updates the label each minute until it gets to less than one minute and it updates the label every second. I'm sure there is a more elegant way of doing 10 down to 2 minutes but I can't think of how to do the math and interpolate the time. Any ideas?
let countdown = 600
func countdownAction() {
countdown -= 1
if countdown > 540 {
label.text = "10 minutes"
} else if countdown > 480 {
label.text = "9 minutes"
} else if countdown > 420 {
label.text = "8 minutes"
} else if countdown > 360 {
label.text = "7 minutes"
} else if countdown > 300 {
label.text = "6 minutes"
} else if countdown > 240 {
label.text = "5 minutes"
} else if countdown > 180 {
label.text = "4 minutes"
} else if countdown > 120 {
label.text = "3 minutes"
} else if countdown > 60 {
label.text = "2 minutes"
} else if countdown > 0 {
label.text = "1 minute"
} else {
label.text = "\(countdown) seconds"
}
}
% 60and/ 60creatively. - RoopeDatepropertytimeIntervalSinceNowto measure it. - Leo Dabus