user594883
user594883

Reputation: 1351

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

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
                    }
                }
            }
        }
    }

Upvotes: 0

Views: 837

Answers (2)

West1
West1

Reputation: 1918

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

Upvotes: 0

OOPer
OOPer

Reputation: 47896

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

Upvotes: 9

Related Questions