diff --git a/src/ui/osx/TogglDesktop/Features/Timer/TimerViewController/TimerViewController.swift b/src/ui/osx/TogglDesktop/Features/Timer/TimerViewController/TimerViewController.swift index b15acbe89c..0900e2dd8d 100644 --- a/src/ui/osx/TogglDesktop/Features/Timer/TimerViewController/TimerViewController.swift +++ b/src/ui/osx/TogglDesktop/Features/Timer/TimerViewController/TimerViewController.swift @@ -114,7 +114,9 @@ class TimerViewController: NSViewController { override func viewDidDisappear() { super.viewDidDisappear() - + + viewModel.viewWillDisappear() + [projectAutocompleteDidResignObserver, tagsAutocompleteDidResignObserver] .compactMap { $0 } .forEach { NotificationCenter.default.removeObserver($0) } diff --git a/src/ui/osx/TogglDesktop/Features/Timer/TimerViewController/TimerViewModel.swift b/src/ui/osx/TogglDesktop/Features/Timer/TimerViewController/TimerViewModel.swift index 3e1816ced3..8fbfbd0961 100644 --- a/src/ui/osx/TogglDesktop/Features/Timer/TimerViewController/TimerViewModel.swift +++ b/src/ui/osx/TogglDesktop/Features/Timer/TimerViewController/TimerViewModel.swift @@ -114,7 +114,7 @@ final class TimerViewModel: NSObject { var tagsDataSource = TagDataSource(items: TagStorage.shared.tags, updateNotificationName: .TagStorageChangedNotification) - private var timer: Timer! + private var timer: Timer? private var actionsUsedBeforeStart: Set = Set() @@ -138,10 +138,14 @@ final class TimerViewModel: NSObject { deinit { cancelNotificationObservers() - timer.invalidate() } // MARK: - Public + + func viewWillDisappear() { + timer?.invalidate() + timer = nil + } func startStopAction() { if timeEntry.isRunning() {