【问题标题】:Xcode 6 sprite kit - SourceKitService terminatedXcode 6 sprite kit - SourceKitService 终止
【发布时间】:2014-07-03 19:39:36
【问题描述】:

当我实现这个方法时,我的 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")
        }
    }
}

【问题讨论】:

  • 这个问题似乎离题了,因为它是关于测试版软件中的一个错误。
  • 所以我们不能在 xcode 6 中实现 func touchesBegan ?
  • @user3722523 可以,但在修复错误之前不进行语法高亮显示

标签: ios swift sourcekit


【解决方案1】:

在 beta4 上运行,我能够毫无问题地声明该方法。 for touch: AnyObject in touches { 看起来是个问题,因为当我用 UITouch 替换 AnyObject 时,这更具体到你想要得到的东西,我得到编译器错误:NSSet! cannot be implicitly downcast to 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 崩溃。也许您在代码中还有其他问题区域?

【讨论】:

    【解决方案2】:

    这个错误也发生在我身上。我现在解决了它,首先将 NSSet 转换为 NSArray,然后使用 for..in 循环方式。这没有崩溃:

    override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {
    
            super.touchesBegan(touches, withEvent: event)
    
            let touchArray: NSArray = touches.allObjects
    
            for element in touchArray {
                println("\(element)")
            }
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多