質問編集履歴
3
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,6 +18,108 @@
|
|
18
18
|
|
19
19
|
```
|
20
20
|
|
21
|
+
import UIKit
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
class ViewController: UIViewController {
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
//タイマー変数を作成
|
30
|
+
|
31
|
+
//Timerクラスを使うと指定した時間になんらかの処理を実行したり、定期的に繰り返したりできる。
|
32
|
+
|
33
|
+
var timer : Timer?
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
//カウント(経過時間)の変数を作成
|
38
|
+
|
39
|
+
//初期値を設定。この場合は0
|
40
|
+
|
41
|
+
var count = 0
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
//設定値を扱うキーを設定
|
46
|
+
|
47
|
+
//秒数を扱う変数
|
48
|
+
|
49
|
+
let settingKey = "timer_value"
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
//ViewControllerの起動時に一度だけ実行される
|
54
|
+
|
55
|
+
override func viewDidLoad() {
|
56
|
+
|
57
|
+
super.viewDidLoad()
|
58
|
+
|
59
|
+
// Do any additional setup after loading the view, typically from a nib.
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
//UserDefaultsのインスタンスを作成
|
64
|
+
|
65
|
+
//UserDefaultsとはアプリで利用していた値を保存できる
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
let settings = UserDefaults.standard
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
//Userdefaultに初期値を登録
|
74
|
+
|
75
|
+
settings.register(defaults: [settingKey:10])
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
override func didReceiveMemoryWarning() {
|
82
|
+
|
83
|
+
super.didReceiveMemoryWarning()
|
84
|
+
|
85
|
+
// Dispose of any resources that can be recreated.
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
@IBOutlet weak var countDownLable: UILabel!
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
@IBAction func settingButtonAction(_ sender: AnyObject) {
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
@IBAction func startButtonAction(_ sender: AnyObject) {
|
104
|
+
|
105
|
+
//timerをアンラップしてnowTimerに代入
|
106
|
+
|
107
|
+
if let nowTimer = timer {
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
if nowTimer.isValid == true {
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
return
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
|
21
123
|
//タイマースタート
|
22
124
|
|
23
125
|
timer = Timer.scheduledTimer(timeInterval:1.0,target: self,selector: #selector(self.timerInterrupt(_:)),userInfo: nil, repeats: true)
|
@@ -144,6 +246,8 @@
|
|
144
246
|
|
145
247
|
}
|
146
248
|
|
249
|
+
|
250
|
+
|
147
251
|
```
|
148
252
|
|
149
253
|
###試したこと
|
2
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
###該当のソースコード
|
18
18
|
|
19
|
-
|
19
|
+
```
|
20
20
|
|
21
21
|
//タイマースタート
|
22
22
|
|
@@ -144,7 +144,7 @@
|
|
144
144
|
|
145
145
|
}
|
146
146
|
|
147
|
-
|
147
|
+
```
|
148
148
|
|
149
149
|
###試したこと
|
150
150
|
|
1
コードの修正以来
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
###該当のソースコード
|
18
18
|
|
19
|
-
|
19
|
+
'''
|
20
20
|
|
21
21
|
//タイマースタート
|
22
22
|
|
@@ -144,7 +144,7 @@
|
|
144
144
|
|
145
145
|
}
|
146
146
|
|
147
|
-
|
147
|
+
'''
|
148
148
|
|
149
149
|
###試したこと
|
150
150
|
|