Unrecognized selector sent to instance NSTimer Swift

人走茶凉 提交于 2019-11-30 20:42:36

let updateTime be a class method .
And if it's in a pure Swift class you'll need to preface that method's declaration with @objc like:

class A {
     @objc func updateTime(timer:NSTimer) {

     }
}

You have defined the updateTime as a local function to Stopwatch, so it is not available outside of its scope. You should move it at class level (same as Stopwatch) in order to be accessible.

I notice however that there are some local variables which should probably be instance properties.

Another possibility: make sure your selector function doesn't throw, as that will also give you an unrecognized selector exception:

func mySelector(timer: NSTimer) throws {
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!