Q:

Updating game score held in SKScene from a SKSpriteNode subclass in Swift

We have a main Game Scene SKScene which holds the HUD logic and score.  
We also have a subclass of SKSpriteNode for an object. When the object is tapped we handle the touch in the SKSpriteNode subclass.  
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {

What we would like to do is update the score held within the gamescene when one is tapped. How can this be accomplished?

A:

I assume that

GameScene has a child SKLabelNode named "scoreLabel"
"scoreLabel" shows the current score of the game
GameScene has a child SKSpriteNode named "mySprite"
When "mySprite" receives a tap, the score must be increased by 1
GameScene has a private property var score = 0

This is how you should implement touchesBegan:withEvent

class GameScene: SKScene {

    private var score = 0

    override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
        if
            let touch = touches.first as? UITouch,
            let tappedSprite = nodeAtPoint(touch.locationInNode(self)) as? SKSpriteNode,
            let scoreLabel = childNodeWithName("scoreLabel") as? SKLabelNode
            where tappedSprite.name == "mySprite" {
                score += 1
                scoreLabel.text = "Score: \(score)"
        }
    }
}

Explanation

The first condition pick the first received touch. If there is at least a touch in touches this will succeed. (And in theory this line will never fail.)
The second condition does retrieve the SKNode that contains the touched point, then tries to cast this node to SKSpriteNode.
The third condition tries to retrieve an SKLabelNode with name "scoreLabel".
The where check that the retrieved sprite has name "mySprite".
If these 4 conditions have success then the private property score is increased by 1 and the text of the label is update.
Hope this helps.

