質問するログイン新規登録

質問編集履歴

3

コード修正

2016/11/21 05:45

投稿

ShintaroOKUMURA
ShintaroOKUMURA

スコア21

title CHANGED
File without changes
body CHANGED
@@ -8,6 +8,57 @@
8
8
  とエラーが出ています。
9
9
  ###該当のソースコード
10
10
  ```
11
+ import UIKit
12
+
13
+ class ViewController: UIViewController {
14
+
15
+ //タイマー変数を作成
16
+ //Timerクラスを使うと指定した時間になんらかの処理を実行したり、定期的に繰り返したりできる。
17
+ var timer : Timer?
18
+
19
+ //カウント(経過時間)の変数を作成
20
+ //初期値を設定。この場合は0
21
+ var count = 0
22
+
23
+ //設定値を扱うキーを設定
24
+ //秒数を扱う変数
25
+ let settingKey = "timer_value"
26
+
27
+ //ViewControllerの起動時に一度だけ実行される
28
+ override func viewDidLoad() {
29
+ super.viewDidLoad()
30
+ // Do any additional setup after loading the view, typically from a nib.
31
+
32
+ //UserDefaultsのインスタンスを作成
33
+ //UserDefaultsとはアプリで利用していた値を保存できる
34
+
35
+ let settings = UserDefaults.standard
36
+
37
+ //Userdefaultに初期値を登録
38
+ settings.register(defaults: [settingKey:10])
39
+ }
40
+
41
+ override func didReceiveMemoryWarning() {
42
+ super.didReceiveMemoryWarning()
43
+ // Dispose of any resources that can be recreated.
44
+ }
45
+
46
+ @IBOutlet weak var countDownLable: UILabel!
47
+
48
+ @IBAction func settingButtonAction(_ sender: AnyObject) {
49
+ }
50
+
51
+
52
+ @IBAction func startButtonAction(_ sender: AnyObject) {
53
+ //timerをアンラップしてnowTimerに代入
54
+ if let nowTimer = timer {
55
+
56
+ if nowTimer.isValid == true {
57
+
58
+ return
59
+ }
60
+ }
61
+
11
62
  //タイマースタート
12
63
  timer = Timer.scheduledTimer(timeInterval:1.0,target: self,selector: #selector(self.timerInterrupt(_:)),userInfo: nil, repeats: true)
13
64
  }
@@ -71,6 +122,7 @@
71
122
  }
72
123
  }
73
124
  }
125
+
74
126
  ```
75
127
  ###試したこと
76
128
  このエラーの意味を調べた所、timerinterruptというメソッドが定義されていないということになっているとわかったのですが、func timerInterruptここで定義しているので問題はないと思うのですが、書き方が違うのか他に何かエラーがあるのかわかりません。

2

コードの修正

2016/11/21 05:45

投稿

ShintaroOKUMURA
ShintaroOKUMURA

スコア21

title CHANGED
File without changes
body CHANGED
@@ -7,7 +7,7 @@
7
7
  ```
8
8
  とエラーが出ています。
9
9
  ###該当のソースコード
10
- '''
10
+ ```
11
11
  //タイマースタート
12
12
  timer = Timer.scheduledTimer(timeInterval:1.0,target: self,selector: #selector(self.timerInterrupt(_:)),userInfo: nil, repeats: true)
13
13
  }
@@ -71,7 +71,7 @@
71
71
  }
72
72
  }
73
73
  }
74
- '''
74
+ ```
75
75
  ###試したこと
76
76
  このエラーの意味を調べた所、timerinterruptというメソッドが定義されていないということになっているとわかったのですが、func timerInterruptここで定義しているので問題はないと思うのですが、書き方が違うのか他に何かエラーがあるのかわかりません。
77
77
 

1

コードの修正以来

2016/11/21 05:44

投稿

ShintaroOKUMURA
ShintaroOKUMURA

スコア21

title CHANGED
File without changes
body CHANGED
@@ -7,7 +7,7 @@
7
7
  ```
8
8
  とエラーが出ています。
9
9
  ###該当のソースコード
10
-
10
+ '''
11
11
  //タイマースタート
12
12
  timer = Timer.scheduledTimer(timeInterval:1.0,target: self,selector: #selector(self.timerInterrupt(_:)),userInfo: nil, repeats: true)
13
13
  }
@@ -71,7 +71,7 @@
71
71
  }
72
72
  }
73
73
  }
74
-
74
+ '''
75
75
  ###試したこと
76
76
  このエラーの意味を調べた所、timerinterruptというメソッドが定義されていないということになっているとわかったのですが、func timerInterruptここで定義しているので問題はないと思うのですが、書き方が違うのか他に何かエラーがあるのかわかりません。
77
77