0

I've got the class Menu: SKScene, then a func touchesBegan inside of it which gives me the error of:

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

Anyway, if I add override in front of the function it says:

Method does not override any method from its superclass.

Any idea? The whole code:

import SpriteKit

class Menu: SKScene {




var title : SKLabelNode?
var start : SKLabelNode?

override func didMoveToView(view: SKView) {

    backgroundColor = SKColor.whiteColor()

    self.title = SKLabelNode(fontNamed: "Chalkduster")
    self.start = SKLabelNode(fontNamed: "Chalkduster")

    self.title!.name = "title"
    self.start!.name = "new"


    self.addChild(self.title!)
    self.addChild(self.start!)
}

    func touchesBegan(touches: NSSet, withEvent even: UIEvent) {

        self.menuHelper(touches)
    }

    func menuHelper(touches: NSSet) {
        for touch in touches {
            let nodeAtTouch = self.nodeAtPoint(touch.locationInNode(self))
            if nodeAtTouch.name == "title" {
                print("Title pressed")
            }
            else if nodeAtTouch.name == "new" {
                print("Start pressed")
            }
        }

    }
Whirlwind
  • 14,286
  • 11
  • 68
  • 157
ffritz
  • 2,180
  • 1
  • 28
  • 64

1 Answers1

2

The signature (from the docs) for this method is...

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

touches is a Set (not NSSet) of UITouch objects and event is an optional UIEvent.

You also need to override it...

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    self.menuHelper(touches)
}
Fogmeister
  • 76,236
  • 42
  • 207
  • 306