Search code examples
swiftuiviewcontrollernstimerdealloc

deinit not called inside uiviewcontroller after pressing back - Swift


I am trying to dealloc / destroy an NSTimer after a user clicks back, but the deinit{...} inside the uiviewcontroller never gets called.


Solution

  • Beware that a view controller going out of the screen does not mean that it will be deallocated afterwards. I would recommend moving the timer dealloc to viewDidDisappear, but obviously it depends what you are using that timer for as well.