ios - Xcode 6 Sprite 套件 - SourceKitService 终止

标签 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")
        }
    }
}

最佳答案

在 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/

相关文章:

ios - UIPageviewcontroller 过渡样式滚动连续

ios - CoreData - NSManagedObject 子对象一次仅存储在一个对象中

swift - 将 CABasicAnimation 添加到子类 UIButton - 如果启用

快速 Split View Controller 默认单元格

objective-c - 构建 SourceKitten 时没有此类模块 SWXMLHash

ios - Swift UIButton 扩展动画覆盖

ios - 同步录音/回放ios

swift - 在 Swift 中使用泛型作为属性类型时出错

arrays - Xcode,大量 NsDictionary 消耗了我所有的 RAM