Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't figure out how to stop timer #36

Open
benpixel opened this issue May 10, 2017 · 0 comments
Open

Can't figure out how to stop timer #36

benpixel opened this issue May 10, 2017 · 0 comments

Comments

@benpixel
Copy link

benpixel commented May 10, 2017

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()
        }
        
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant