Protocol extension and addTarget is crashing with message: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Test.UIButton touchDown:]: unrecognized selector sent to instance 0x157eee8e0'
Where is the problem that touchDown function is unrecognized?
protocol MyButtonProtocol {
var holdTimer: NSTimer? { get set }
}
extension MyButtonProtocol where Self: UIButton {
func enable() {
addTarget(self, action: "touchDown:", forControlEvents: UIControlEvents.TouchDown)
}
mutating func touchDown(sender: UIButton) {
print("Touch down!")
holdTimer = NSTimer(timeInterval: 1, target: self, selector: Selector("didTimeOut"), userInfo: nil, repeats: true)
}
}
// Usage:
let button = UIButton()
button.enable()