Created
October 29, 2015 04:48
-
-
Save hanksudo/d9d964abb76632e60957 to your computer and use it in GitHub Desktop.
(Swift) NSTimer count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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