Xcode 6精灵工具包 - SourceKitService终止

时间:2014-07-03 19:39:36

标签: ios swift sourcekit

当我实现此方法时,我终止了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")
        }
    }
}

2 个答案:

答案 0 :(得分:0)

在beta4上运行,我能够毫无问题地声明该方法。 for touch: AnyObject in touches {看起来是个问题,因为当我用AnyObject替换UITouch时,我会得到编译错误: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崩溃。也许你在代码中有其他问题区域?

答案 1 :(得分:0)

这个错误也发生在我身上。我现在解决了这个问题,首先将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)")
        }

    }