我在实现此方法时终止了 SourceKitService:
override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!)
如果我删除 ! ,它会起作用。 但是后来我的代码当然出错了。 完整代码:
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")
}
}
}
最佳答案
在 beta4 上运行,我能够毫无问题地声明该方法。 for touch: AnyObject in touches {
看起来是个问题,因为当我将 AnyObject
替换为 UITouch
时,它更符合您的需求得到,我得到编译器错误:NSSet!不能隐式向下转换为 UITouch
,这意味着语法会尝试将数组转换为类型。似乎还不可能转换该元素。参见 Annotation error in Swift for loop with array and UIView .这是没有编译器错误的相同主体代码:
for item in touches {
let location = (item as UITouch).locationInNode(self)
if self.nodeAtPoint(location).name == "plane" {
println("plane touched")
}
}
错误不足以触发我的 SourceKit 崩溃。也许您在代码中还有其他问题区域?
关于ios - Xcode 6 Sprite 套件 - SourceKitService 终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24562062/