Search code examples
iosswiftuigesturerecognizeruitapgesturerecognizer

Overriding touchesBegan: Error - method does not override any method from superclass


I am trying to override touchesBegan in a custom subclass of UITapGestureRecognizer. Code is below. I got it from here: How to accelerate the identification of a single tap over a double tap?. It was the accepted answer, but i am getting an error: method does not override any method from its superclass. I have checked and this indeed seems to be the signature for touchesBegan. Help?

import UIKit

class UIShortTapGestureRecognizer: UITapGestureRecognizer {
    let tapMaxDelay: Double = 0.3

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        super.touchesBegan(touches, withEvent: event)
        delay(tapMaxDelay) {
        // Enough time has passed and the gesture was not recognized -> It has failed.
            if  self.state != UIGestureRecognizerState.Ended {
                self.state = UIGestureRecognizerState.Failed
            }
        }
    }


}

Solution

  • I was indeed using Xcode 7.2 with Swift 2.0. And removing the override keyboard was not the solution. Instead, I found that the solution was to add import UIKit.UIGestureRecognizerSubclass. That also allowed me to write over the state property, rather than it being read-only.