Timer doesn't quit

I have a timer that runs ok. However, when I try to stop the timer, neither function is executed. The code is as follows:

`   func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
        print(#function)
        menuTimer = nil
        menuTimer?.invalidate()
        
       
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        print(#function)
        super.viewDidDisappear(animated)
        menuTimer = nil
        menuTimer?.invalidate()
        
    }

Is this a known issue or am i doing something wrong.

  • Thanks for your reply! It makes sense, however the two functions are still not called.

Add a Comment

Replies

Look closer at these lines:

menuTimer = nil
menuTimer?.invalidate()

When executed in that order, would they actually invalidate the timer?

Got it. I forgot to override viewWillDisappear