From c7da88a428440eb06f861c11996e4358f201e97a Mon Sep 17 00:00:00 2001 From: Michael Villar Date: Wed, 30 Mar 2016 23:42:43 -0700 Subject: [PATCH] Fixed crash --- Timer/MVClockView.swift | 18 +++++++++++------- Timer/MVTimerController.swift | 5 +++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Timer/MVClockView.swift b/Timer/MVClockView.swift index e9dae1c..8c8f9bb 100644 --- a/Timer/MVClockView.swift +++ b/Timer/MVClockView.swift @@ -115,6 +115,8 @@ class MVClockView: NSControl { deinit { let nc = NSNotificationCenter.defaultCenter() nc.removeObserver(self) + + arrowView.target = nil } func windowFocusChanged(notification: NSNotification) { @@ -159,8 +161,7 @@ class MVClockView: NSControl { self.seconds = seconds self.updateTimerTime() - self.timer?.invalidate() - self.timer = nil + self.stop() self.paused = false } @@ -176,8 +177,7 @@ class MVClockView: NSControl { self.start() } else { self.paused = true - self.timer?.invalidate() - self.timer = nil + self.stop() } } @@ -249,15 +249,19 @@ class MVClockView: NSControl { return } self.paused = false - self.timer?.invalidate() + self.stop() self.timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: #selector(tick), userInfo: nil, repeats: true) } + func stop() { + self.timer?.invalidate() + self.timer = nil + } + func tick() { self.seconds = self.seconds - 1 if self.seconds <= 0 { - self.timer?.invalidate() - self.timer = nil + self.stop() self.target?.performSelector(self.action, withObject: self) } } diff --git a/Timer/MVTimerController.swift b/Timer/MVTimerController.swift index 40f89dd..5be3423 100644 --- a/Timer/MVTimerController.swift +++ b/Timer/MVTimerController.swift @@ -34,6 +34,11 @@ class MVTimerController: NSWindowController { } } + deinit { + self.clockView.target = nil + self.clockView.stop() + } + func handleClockTimer(clockView: MVClockView) { let notification = NSUserNotification() notification.title = "It's time! 🕘"