SwiftyTimer icon indicating copy to clipboard operation
SwiftyTimer copied to clipboard

Can't figure out how to stop timer

Open benpixel opened this issue 8 years ago • 0 comments

Hello!

I want to make a function that starts the timer unless there is a bool true in params (e.g. animateStatusIcon(stop: true)) - in that case I want to stop the timer. Does anyone have an idea what's going on here?

The timer starts but no matter what I do it wont stop.

func animateStatusIcon(stop: Bool? = nil){
        
        let icon = NSImage(named: "statusIcon")
        let iconActive = NSImage(named: "statusIconActive")
        
        let timer = Timer.every(0.4.seconds) {
            self.statusItem.image = icon
            Timer.after(0.2.seconds) {
                self.statusItem.image = iconActive
            }
        }
            
        if(stop == true){
            print(stop!)
            print("should stop now")
            timer.invalidate()
        } else  {
            print(stop)
            print("start")
            timer.start()
        }
        
    }

benpixel avatar May 10 '17 15:05 benpixel