質問編集履歴
1
coinCount = coinCount % 3 を追加したら、エラーが出ました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -143,3 +143,77 @@
|
|
143
143
|
|
144
144
|
|
145
145
|
ここにより詳細な情報を記載してください。
|
146
|
+
|
147
|
+
```ここに言語名を入力
|
148
|
+
|
149
|
+
import UIKit
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
class ViewController: UIViewController {
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
override func viewDidLoad() {
|
158
|
+
|
159
|
+
super.viewDidLoad()
|
160
|
+
|
161
|
+
// Do any additional setup after loading the view.
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
@IBOutlet weak var coin: UIImageView!
|
168
|
+
|
169
|
+
var coinCount = 0
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
@IBAction func tapCoin(_ sender: Any) {
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
if coinCount == 0 { ↓エラーが出ます。
|
180
|
+
|
181
|
+
coin.image = UIImage(named: "myImage") __ =Thread 1: Fatal error:__
|
182
|
+
|
183
|
+
__ Unexpectedly found nil while implicitly unwrapping an Optional value__
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
} else if coinCount == 1 {
|
188
|
+
|
189
|
+
coin.image = UIImage(named: "myImage2")
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
} else if coinCount == 2 {
|
194
|
+
|
195
|
+
coin.removeFromSuperview()
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
coinCount = coinCount + 1
|
202
|
+
|
203
|
+
coinCount = coinCount % 3
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
```
|