Skip to content

Instantly share code, notes, and snippets.

@shoya140
Last active August 29, 2015 14:22
Show Gist options
  • Save shoya140/2de362616575f7bad2e4 to your computer and use it in GitHub Desktop.
Save shoya140/2de362616575f7bad2e4 to your computer and use it in GitHub Desktop.
爆速タイマー
import UIKit
class TimerViewController: UIViewController {
@IBOutlet weak var counetrLabel: UILabel!
var counter: Float = 0.0
var stepCounter: Int = 0
var timer: NSTimer?
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func addtimer(sender: AnyObject) {
timer = NSTimer.scheduledTimerWithTimeInterval(0.1,
target: self,
selector: Selector("updateCounter"),
userInfo: nil,
repeats: true
)
timer!.fire()
}
func updateCounter() {
counter += 0.1
self.counetrLabel.text = NSString(format: "%.1f", counter) as String
if Int(counter) > stepCounter {
stepCounter = Int(counter)
println("do something: \(stepCounter)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment