質問編集履歴

1

2015/03/20 02:24

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- swift 電卓を作ってみたのですが...
1
+ 電卓を作ってみたのですが...
test CHANGED
@@ -1,6 +1,6 @@
1
1
  swift初心者です。
2
2
 
3
- 今回、swiftで簡単な電卓を作ってみたのですが、AppDelegate\.swiftでエラーが起きてしまいアプリが中断されてしまいます。
3
+ 今回、swiftで簡単な電卓を作ってみたのですが、AppDelegate.swiftでエラーが起きてしまいアプリが中断されてしまいます。
4
4
 
5
5
  エラー内容はclass AppDelegate: UIResponder, UIApplicationDelegate の行で以下のようなエラー文でした。
6
6
 
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
 
13
- そして、下にはViewController\.swiftのソースを載せます。```lang-swift
13
+ そして、下にはViewController.swiftのソースを載せます。```lang-swift
14
14
 
15
15
  import UIKit
16
16
 
@@ -20,53 +20,53 @@
20
20
 
21
21
 
22
22
 
23
- override func viewDidLoad\(\) {
23
+ override func viewDidLoad() {
24
-
24
+
25
- super\.viewDidLoad\(\)
25
+ super.viewDidLoad()
26
-
26
+
27
- // Do any additional setup after loading the view, typically from a nib\.
27
+ // Do any additional setup after loading the view, typically from a nib.
28
-
28
+
29
- myButton0\.addTarget\(self, action: "buttonClicked", forControlEvents: \.TouchUpInside\)
29
+ myButton0.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
30
-
30
+
31
- myButton1\.addTarget\(self, action: "buttonClicked", forControlEvents: \.TouchUpInside\)
31
+ myButton1.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
32
-
32
+
33
- myButton2\.addTarget\(self, action: "buttonClicked", forControlEvents: \.TouchUpInside\)
33
+ myButton2.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
34
-
34
+
35
- myButton3\.addTarget\(self, action: "buttonClicked", forControlEvents: \.TouchUpInside\)
35
+ myButton3.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
36
-
36
+
37
- myButton4\.addTarget\(self, action: "buttonClicked", forControlEvents: \.TouchUpInside\)
37
+ myButton4.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
38
-
38
+
39
- myButton5\.addTarget\(self, action: "buttonClicked", forControlEvents: \.TouchUpInside\)
39
+ myButton5.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
40
-
40
+
41
- myButton6\.addTarget\(self, action: "buttonClicked", forControlEvents: \.TouchUpInside\)
41
+ myButton6.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
42
-
42
+
43
- myButton7\.addTarget\(self, action: "buttonClicked", forControlEvents: \.TouchUpInside\)
43
+ myButton7.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
44
-
44
+
45
- myButton8\.addTarget\(self, action: "buttonClicked", forControlEvents: \.TouchUpInside\)
45
+ myButton8.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
46
-
46
+
47
- myButton9\.addTarget\(self, action: "buttonClicked", forControlEvents: \.TouchUpInside\)
47
+ myButton9.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
48
48
 
49
49
 
50
50
 
51
- myButtonPlus\.addTarget\(self, action: "buttonClicked", forControlEvents: \.TouchUpInside\)
51
+ myButtonPlus.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
52
-
52
+
53
- myButtonMinus\.addTarget\(self, action: "buttonClicked", forControlEvents: \.TouchUpInside\)
53
+ myButtonMinus.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
54
-
54
+
55
- myButtonMulti\.addTarget\(self, action: "buttonClicked", forControlEvents: \.TouchUpInside\)
55
+ myButtonMulti.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
56
-
56
+
57
- myButtonDivision\.addTarget\(self, action: "buttonClicked", forControlEvents: \.TouchUpInside\)
57
+ myButtonDivision.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
58
-
58
+
59
- myButtonEqual\.addTarget\(self, action: "buttonClicked", forControlEvents: \.TouchUpInside\)
59
+ myButtonEqual.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
60
60
 
61
61
  }
62
62
 
63
63
 
64
64
 
65
- override func didReceiveMemoryWarning\(\) {
65
+ override func didReceiveMemoryWarning() {
66
-
66
+
67
- super\.didReceiveMemoryWarning\(\)
67
+ super.didReceiveMemoryWarning()
68
-
68
+
69
- // Dispose of any resources that can be recreated\.
69
+ // Dispose of any resources that can be recreated.
70
70
 
71
71
  }
72
72
 
@@ -114,13 +114,13 @@
114
114
 
115
115
 
116
116
 
117
- func buttonClicked\(sender: UIButton\){
117
+ func buttonClicked(sender: UIButton){
118
118
 
119
119
  switch sender {
120
120
 
121
121
  case myButtonPlus,myButtonMinus,myButtonMulti,myButtonDivision:
122
122
 
123
- command = sender\.titleLabel!\.text!;
123
+ command = sender.titleLabel!.text!;
124
124
 
125
125
  inputR = true;//右辺の入力に移る
126
126
 
@@ -132,27 +132,27 @@
132
132
 
133
133
  if inputR {
134
134
 
135
- var result: Int\?;
135
+ var result: Int?;
136
136
 
137
137
 
138
138
 
139
139
  switch command {
140
140
 
141
- case "\+":
141
+ case "+":
142
-
142
+
143
- result = left\.toInt\(\)! \+ right\.toInt\(\)!;
143
+ result = left.toInt()! + right.toInt()!;
144
144
 
145
145
  case "-":
146
146
 
147
- result = left\.toInt\(\)! - right\.toInt\(\)!;
147
+ result = left.toInt()! - right.toInt()!;
148
-
148
+
149
- case "\*":
149
+ case "*":
150
-
150
+
151
- result = left\.toInt\(\)! \* right\.toInt\(\)!;
151
+ result = left.toInt()! * right.toInt()!;
152
152
 
153
153
  case "/":
154
154
 
155
- result = left\.toInt\(\)! / right\.toInt\(\)!;
155
+ result = left.toInt()! / right.toInt()!;
156
156
 
157
157
 
158
158
 
@@ -162,7 +162,7 @@
162
162
 
163
163
  }
164
164
 
165
- myLabel\.text = "\\\(result\)";//結果の表示
165
+ myLabel.text = "\(result)";//結果の表示
166
166
 
167
167
  //次の入力のためのデータの初期化
168
168
 
@@ -184,17 +184,17 @@
184
184
 
185
185
  //右辺入力時の動作
186
186
 
187
- right = right \+ sender\.titleLabel!\.text!;
187
+ right = right + sender.titleLabel!.text!;
188
-
188
+
189
- myLabel\.text = right;
189
+ myLabel.text = right;
190
190
 
191
191
  } else {
192
192
 
193
193
  //左辺入力中なら
194
194
 
195
- left = left \+ sender\.titleLabel!\.text!;
195
+ left = left + sender.titleLabel!.text!;
196
-
196
+
197
- myLabel\.text = left;
197
+ myLabel.text = left;
198
198
 
199
199
 
200
200