. Advertisement .
..3..
. Advertisement .
..4..
I am very confused about countdown timer in swift. Can you instruct some methods that will lead to a conclusion?
Here is an example code.var remainTime = 40
@IBOutlet var timerTextField: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
var countDownTimer = Timer.scheduledTimer(target: self, timeInterval: 0.5, userInfo: nil, repeats: true)
if(remainTime > 0) {
timerTextField.text = String((remainTime--)
} else {
countDownTimer.invalidate()
}
}
Here is the code that I referenced on stackoverflow.com
Create a countdown timer
Everything will be made clear to you via the following way.