0
votes

I have timerRunner() function that runs when button is clicked:

func timerRunner() {
        timer = Timer.scheduledTimer(timeInterval: 1.0, target: target.self, selector: (#selector(self.timeUpdater)), userInfo: nil, repeats: true)
    }

Selector of Timer.scheduledTimer is selected as following:

@objc func timeUpdater() {
    counter = counter + 1

    timerLabel.text = secondConverter(seconds: counter)

}

But this is an error message I get:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue timeUpdater]: unrecognized selector sent to instance '

1
What is target.self in your code? Why not simply self as you use #selector(self.timeUpdater) ? - OOPer

1 Answers

0
votes

As far as I know, timeUpdater function should have one argument of type Timer. Something like that:

@objc func timeUpdater(_ timer: Timer) {
    counter = counter + 1
    timerLabel.text = secondConverter(seconds: counter)
}