I'm not sure why but every time I run my application, my timer will not call the update function. I have tried everything: using #selector, adding a colon at the end of update, nothing is working. I have added a print statement inside my update to make sure that it reaches there, and the print statement never prints! I'm not sure why it isn't being called.... Help! P.S. I know selected is indeed one of the options in the if statement, I had a print statement for that and it's working.
if (selected == "05 seconds") { count = 5 timer = Timer(timeInterval: 1.0, target: self, selector: Selector("update"), userInfo: nil, repeats: true) } else if (selected == "10 seconds") { count = 10 timer = Timer(timeInterval: 1.0, target: self, selector: Selector("update"), userInfo: nil, repeats: true) } else if (selected == "20 seconds") { count = 20 timer = Timer(timeInterval: 1.0, target: self, selector: Selector("update"), userInfo: nil, repeats: true) } else if (selected == "30 seconds") { print("I'm here!") count = 30 timer = Timer(timeInterval: 1.0, target: self, selector: Selector("update"), userInfo: nil, repeats: true) } else if (selected == "Single Shot") { SendButton.isHidden = false countDownLabel.isHidden = true } } func update() { print("Now I'm in update!") count = count - 1; countDownLabel.text = String(count) }
#selector(update(_:)). That way you can pass the sender to the function.