如何停止'enumerateChildNodesWithName("//*")'枚举?

How to stop ´enumerateChildNodesWithName("//*") ´ enumeration?

如何停止此枚举?我有以下代码和 Xcode 抱怨我不能给 let 常量赋值。停止可能是一件简单的事情,但我是 Swift 的菜鸟,所以请多多包涵。

self.enumerateChildNodesWithName("//*") {
        spaceshipNode, stop in
        if (( spaceshipNode.name?.hasSuffix("ship") ) != nil) {
            for enemyNode in self.children {
                if (enemyNode.name == "enemy"){
                    if(enemyNode.containsPoint(spaceshipNode.position)){
                        self.gotoGameOverScene(spaceshipNode)
                        stop = true // Error: Cannot assign to value: 'stop' is a 'let' constant
                    }
                }
            }
        }
    }

通常您最好将代码显示为文本。有了它,我们可以轻松地复制和粘贴,测试它,或编辑它。

在您的代码中,stop 的类型在 Xcode 的快速帮助窗格中应显示为 UnsafeMutablePointer<ObjCBool>

需要修改指针的内容,在Swift2:

            stop.memory = true

在Swift3中,属性memory重命名为pointee:

            stop.pointee = true

苹果的documentation建议我们通过stop.initialize(to: true)停止枚举。