2

I got SourceKitService terminated when I implement this method:

override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!)

if I remove the ! , it works. But then I got an error in my code of course. Full code:

override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {

    for touch: AnyObject in touches {

        let location = touch.locationInNode(self)

        if nodeAtPoint(location).name == "plane" {
            println("plane touched")
        }
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
user3722523
  • 1,740
  • 2
  • 15
  • 27

2 Answers2

0

Running on beta4, and I was able to declare the method without issue. for touch: AnyObject in touches { looks to be the issue, since when I replace AnyObject with UITouch, which is more specific to what you want to get, I get the compiler error: NSSet! cannot be implicitly downcast to UITouch, which means that syntax tries to cast the array to the type. It would seem casting the item isn't possible yet. See Annotation error in Swift for loop with array and UIView. Here's the same body code without compiler errors:

for item in touches {

    let location = (item as UITouch).locationInNode(self)    

    if self.nodeAtPoint(location).name == "plane" {
        println("plane touched")
    }

}

The errors weren't enough to trigger the SourceKit crash for me. Maybe you have other problem areas in the code?

Community
  • 1
  • 1
hlfcoding
  • 2,532
  • 1
  • 21
  • 25
0

This error happened to me also. I solved it for now, by first converting the NSSet to an NSArray and then use the for..in way of looping. This didn't crash:

override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {

        super.touchesBegan(touches, withEvent: event)

        let touchArray: NSArray = touches.allObjects

        for element in touchArray {
            println("\(element)")
        }

    }
Thorsten Viel
  • 1,199
  • 1
  • 10
  • 18