I can not invalidate a Swift Timer.
When defining my objects and variables I declare the timer with
var scoreTimer = Timer()
I start the timer when two objects collide with this line:
scoreTimer = Timer.scheduledTimer(timeInterval: 0.05, target: self, selector: #selector(updatePassengerScore), userInfo: nil, repeats: true)
My updatePassengerScore method looks like this
passengerScore -= 1
scoreLabel.text = String(passengerScore)
When another collision is detected, I try to stop the timer with
scoreTimer.invalidate()
but the variable passengerScore is still decreasing and I do not have a clue why this is the case. Does anyone have a clue hoe to solve this and make the Timer stop? Every Thread I read says that scoreTimer.invalidate() should actually stop the timer. I am really confused :-/