How can I make a countdown with NSTimer?

Giovanie Rodz picture Giovanie Rodz · Mar 31, 2015 · Viewed 95.6k times · Source

How can I make a countdown with an NSTimer using Swift?

Answer

Bigman picture Bigman · Mar 31, 2015

Question 1:

@IBOutlet var countDownLabel: UILabel!

var count = 10

override func viewDidLoad() {
    super.viewDidLoad()

    var timer = Timer.scheduledTimer(timeInterval: 0.4, target: self, selector: #selector(UIMenuController.update), userInfo: nil, repeats: true)
}

func update() {
    if(count > 0) {
        countDownLabel.text = String(count--)
    }
}

Question 2:

You can do both. SpriteKit is the SDK you use for scene, motion, etc. Simple View Application is the project template. They should not conflict