Skip to content

Instantly share code, notes, and snippets.

@hanksudo
Created October 29, 2015 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanksudo/d9d964abb76632e60957 to your computer and use it in GitHub Desktop.
Save hanksudo/d9d964abb76632e60957 to your computer and use it in GitHub Desktop.
(Swift) NSTimer count
import UIKit
class ViewController: UIViewController {
var timer = NSTimer()
var count = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
timer = NSTimer(timeInterval: 2.0, target: self, selector: "countUp", userInfo: nil, repeats: true)
NSRunLoop.currentRunLoop().addTimer(timer, forMode: NSRunLoopCommonModes)
}
func countUp() {
count++
print("\(count)")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment