Swift 2.0:覆盖超类的错误消息

Swift 2.0: Override error message for superclass

切换到Swift2.0后

  override public func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent)  {
    userInteractionBegan(touches.first as! UITouch)
  }

产生一条错误消息:

Method class does not override any method from its superclass

我不知道为什么覆盖不再覆盖!

在swift中,方法签名被更改为更多"swiftier"。这是您应该覆盖的新方法签名:

override public func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

}

在Swift2中,touchesBegan方法有变化。现在第一个参数是 Set<UITouch> 而不是 NSObject。所以 Swift 告诉你你试图覆盖一个不存在的方法。使用 Set<UITouch> 代替:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
                                        ^^^^^^^
}