質問編集履歴
1
ソースコードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -53,5 +53,51 @@
|
|
53
53
|
今のところドットインストールをに従って作成しており、swiftのバージョンの関係上ソースコードを以下のように書き換えた。
|
54
54
|
|
55
55
|
```
|
56
|
+
import UIKit
|
57
|
+
|
58
|
+
class ViewController: UIViewController {
|
59
|
+
|
60
|
+
@IBOutlet weak var timerLabel: UILabel!
|
61
|
+
@IBOutlet weak var startButton: UIButton!
|
62
|
+
@IBOutlet weak var stopButton: UIButton!
|
63
|
+
@IBOutlet weak var resetButton: UIButton!
|
64
|
+
|
65
|
+
var starttime: NSTimeInterval? = nil
|
66
|
+
var timer: NSTimer?
|
67
|
+
|
68
|
+
override func viewDidLoad() {
|
69
|
+
super.viewDidLoad()
|
70
|
+
// Do any additional setup after loading the view, typically from a nib.
|
71
|
+
}
|
72
|
+
|
73
|
+
override func didReceiveMemoryWarning() {
|
74
|
+
super.didReceiveMemoryWarning()
|
75
|
+
// Dispose of any resources that can be recreated.
|
76
|
+
}
|
77
|
+
|
78
|
+
func update() {
|
79
|
+
if let t = self.starttime {
|
80
|
+
let time: Double = NSDate.timeIntervalSinceReferenceDate() - t
|
81
|
+
let sec: Int = Int(time)
|
82
|
+
let msec: Int = Int((time - Double(sec)) * 100.0)
|
83
|
+
self.timerLabel.text = NSString(format: "%02d:%02d:%02d", sec/60, sec%60, msec) as String
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
@IBAction func startTimer(sender: AnyObject) {
|
88
|
+
self.starttime = NSDate.timeIntervalSinceReferenceDate()
|
56
|
-
self.timer = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: #selector(ViewController.update), userInfo: nil, repeats: true)
|
89
|
+
self.timer = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: #selector(ViewController.update), userInfo: nil, repeats: true)
|
90
|
+
}
|
91
|
+
|
92
|
+
@IBAction func stopTimer(sender: AnyObject) {
|
93
|
+
|
94
|
+
}
|
95
|
+
|
96
|
+
@IBAction func resetTimer(sender: AnyObject) {
|
97
|
+
|
98
|
+
}
|
99
|
+
|
100
|
+
}
|
101
|
+
|
102
|
+
|
57
103
|
```
|