Need help to make a countdown timer that waits until it is invalidated to proceed. It also should not be blocking main thread. Any tips?
private var currentCountdownSeconds = 3
private var countdownTimer = Timer()
private func performTimer() {
if secondsToCountDown != 0 {
print(secondsToCountDown)
countdownTimer = Timer(timeInterval: 1, target: self, selector: #selector(handleCountdown), userInfo: nil, repeats: true)
}
}
@objc private func handleCountdown() {
previewView.countdownLabel.text = "\(currentCountdownSeconds)"
currentCountdownSeconds -= 1
print(secondsToCountDown)
if secondsToCountDown == 0 {
countdownTimer.invalidate()
}
}
public func toggleMovieRecording() {
handleTimer()
videoCaptureLogic()
}
public func toggleCapturePhoto() {
handleTimer()
videoCaptureLogic()
}