Katherine Jenkins Katherine Jenkins - 5 months ago 95x
Swift Question

NSTimer Countdown - updateCounter Swift 3.0 New Syntax?

I have a simple countdown timer. And a label that displays the countdown.

var SwiftTimer = NSTimer()
var SwiftCounter = 60

override func viewDidLoad() {

timerLabel.text = String(SwiftCounter)


I reduce the counter by one second. This function gives me an error:

func updateCounter() {
timerLabel.text = String(SwiftCounter--)

Erro states:

'--' is deprecated: it will be removed in Swift 3

I realise I have to convert
it to
x -= 1
(x is the variable). I have tried

func updateCounter() {
timerLabel.text = String(SwiftCounter -= 1)


to reduce the counter by 1 second, but my counter (timerLabel) just goes blank.

What is the new Swift syntax for my situation please?


You should separate the logic onto 2 lines, because you're decrementing and saving and then converting to string for display and that's 2 different things:

SwiftCounter -= 1
timerLabel.text = String(SwiftCounter)