Last active
August 29, 2015 14:22
-
-
Save shoya140/2de362616575f7bad2e4 to your computer and use it in GitHub Desktop.
爆速タイマー
This file contains hidden or 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 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