0

I'm having a really weird behaviour with those two functions, when I declare them like this:

override func touchesBegin(touches: NSSet, withEvent event: UIEvent)
override func touchesMoved(touches: NSSet, withEvent event: UIEvent)

I get error message which says:

Method does not override any method from its superclass

However when I declare them like this:

func touchesBegin(touches: NSSet, withEvent event: UIEvent)
func touchesMoved(touches: NSSet, withEvent event: UIEvent)

I get error message which says:

Method 'touchesBegan(_:withEvent:)' with Objective-C selector 'touchesBegan:withEvent:' conflicts with method 'touchesBegan(_:withEvent:)' from superclass 'UIResponder' with the same Objective-C selector

Method 'touchesMoved(_:withEvent:)' with Objective-C selector 'touchesMoved:withEvent:' conflicts with method 'touchesMoved(_:withEvent:)' from superclass 'UIResponder' with the same Objective-C selector

So do I or don't I override the function from superclass?

Jakub Zak
  • 1,212
  • 6
  • 32
  • 53

1 Answers1

2

I think the method signatures you are looking for are:

class XXX : UIResponder {

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

    }

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

    }

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

    }

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

    }
}
Mike Pollard
  • 10,195
  • 2
  • 37
  • 46