Swift 4: Timer Crashing - unrecognized selector sent to instance

后端 未结 1 401
轮回少年
轮回少年 2021-01-21 10:57

I\'m trying to call an instance of Timer and print \"A second has passed\" for each second that elapses. I\'m following The Complete iOs 11 & Swift Developer Course on Udemy

相关标签:
1条回答
  • 2021-01-21 11:26

    The callback function processTimer is not correctly declared:

    @objc func processTimer() {
       //your code here
    }
    

    You need to add the @objc keyword before the function in order to be called in the Timer callback. Also, in general I think is better to use #selector keyword instead.

    0 讨论(0)
提交回复
热议问题