Skip to content

Commit

Permalink
Fixed crash
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelvillar committed Mar 31, 2016
1 parent 22fba09 commit c7da88a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Timer/MVClockView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class MVClockView: NSControl {
deinit {
let nc = NSNotificationCenter.defaultCenter()
nc.removeObserver(self)

arrowView.target = nil
}

func windowFocusChanged(notification: NSNotification) {
Expand Down Expand Up @@ -159,8 +161,7 @@ class MVClockView: NSControl {
self.seconds = seconds
self.updateTimerTime()

self.timer?.invalidate()
self.timer = nil
self.stop()

self.paused = false
}
Expand All @@ -176,8 +177,7 @@ class MVClockView: NSControl {
self.start()
} else {
self.paused = true
self.timer?.invalidate()
self.timer = nil
self.stop()
}
}

Expand Down Expand Up @@ -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)
}
}
Expand Down
5 changes: 5 additions & 0 deletions Timer/MVTimerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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! 🕘"
Expand Down

0 comments on commit c7da88a

Please sign in to comment.