You can do this in a few ways, and here is an example on how to update label text (counter) using SKAction:
import SpriteKit
class GameScene: SKScene {
let timeLabel = SKLabelNode(fontNamed: "Geneva")
var counter = 60
override func didMoveToView(view: SKView) {
timeLabel.text = "60"
timeLabel.position = CGPointMake(frame.midX, frame.midY)
timeLabel.fontColor = UIColor.blackColor()
timeLabel.fontSize = 40
self.addChild(timeLabel)
}
func countdown(){
let updateCounter = SKAction.runBlock({
self.timeLabel.text = "\(self.counter--)"
if(self.counter == 0){
self.counter = 60
}
})
timeLabel.text = "60"
timeLabel.position = CGPointMake(frame.midX, frame.midY)
timeLabel.fontColor = UIColor.blackColor()
timeLabel.fontSize = 40
let countdown = SKAction.repeatActionForever(SKAction.sequence([SKAction.waitForDuration(1),updateCounter]))
//You can run an action with key. Later, if you want to stop the timer, are affect in any way on this action, you can access it by this key
timeLabel.runAction(countdown, withKey:"countdown")
}
func stop(){
if(timeLabel.actionForKey("countdown") != nil){
timeLabel.removeActionForKey("countdown")
}
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
if(timeLabel.actionForKey("countdown") == nil){
self.countdown()
}
}
}
What I am doing here is updating a label's text property each second. To achieve that, I've created a block of code which updates a counter variable. That block of code is called each second using the action sequence.
Note that your current code trying to add label in each loop. Node can have only one parent, and like the app will crash with following error message :
Attemped to add a SKNode which already has a parent
Also you are not running updating label's text property once in a second. You are executing the whole for loop at once (which is done in much less time then a second).