0

How do I stop this enumeration? I have the following code and Xcode complaining that I cannot assign a value to let constant. Stopping is probably a simple thing but I'm quite the noobie with Swift, so please bear with me.

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
                    }
                }
            }
        }
    }
peacetype
  • 1,928
  • 3
  • 29
  • 49
user594883
  • 1,329
  • 2
  • 17
  • 36

2 Answers2

9

Generally you'd better show your code as text. With which we can easily copy & paste, and test it, or edit it.

In your code, the type of stop should be shown as UnsafeMutablePointer<ObjCBool> in the Quick Help pane of Xcode.

You need to modify the content of the pointer, in Swift2:

            stop.memory = true

In Swift 3, the property memory is renamed to pointee:

            stop.pointee = true
OOPer
  • 47,149
  • 6
  • 107
  • 142
0

Apple's documentation suggests that we stop enumeration via stop.initialize(to: true).

West1
  • 1,430
  • 16
  • 27