質問編集履歴
4
削除の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,3 +1,134 @@
|
|
1
|
+
###前提・実現したいこと
|
2
|
+
今カルタの文を読んでくれるアプリ?を作っています。今できているところは48種類のカルタの文をランダムに読んでくれるところです。しかし、一度読んだ文もまた繰り返されます。それを一度読んだものはもう読まないようにしたいです。
|
3
|
+
|
4
|
+
|
5
|
+
ボタンを押すと次の文と最初の文字を表示しその文を
|
6
|
+
読み上げてくれるようになっています。
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
###該当のソースコード
|
1
|
-
swift
|
12
|
+
```swift
|
13
|
+
import UIKit
|
14
|
+
|
15
|
+
import AVFoundation
|
16
|
+
|
17
|
+
class ViewController: UIViewController {
|
18
|
+
|
19
|
+
@IBOutlet weak var QuestionLabel: UILabel!
|
20
|
+
|
21
|
+
@IBOutlet weak var Button1: UIButton!
|
22
|
+
|
23
|
+
@IBOutlet weak var Next: UIButton!
|
24
|
+
|
25
|
+
var CorrectAnswer = String\(\)
|
26
|
+
|
27
|
+
override func viewDidLoad\(\) {
|
28
|
+
super\.viewDidLoad\(\)
|
29
|
+
|
30
|
+
Hide\(\)
|
31
|
+
RandomQuestions\(\)
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
override func didReceiveMemoryWarning\(\) {
|
36
|
+
super\.didReceiveMemoryWarning\(\)
|
37
|
+
|
38
|
+
}
|
2
|
-
|
39
|
+
func RandomQuestions\(\){
|
40
|
+
|
41
|
+
var RandomNumber = arc4random\(\) % 48
|
42
|
+
|
43
|
+
RandomNumber \+= 1
|
44
|
+
|
45
|
+
switch \(RandomNumber\) {
|
46
|
+
|
47
|
+
case 1:
|
48
|
+
|
49
|
+
QuestionLabel\.text = "モンゴルの民族模様は自由の印"
|
50
|
+
Button1\.setTitle\("も", for: \.normal\)
|
51
|
+
//文を読む
|
52
|
+
let synthesizer = AVSpeechSynthesizer\(\)
|
53
|
+
let utterance = AVSpeechUtterance\(string: "モンゴルの民族模様は自由の印。"\)
|
54
|
+
synthesizer\.speak\(utterance\)
|
55
|
+
|
56
|
+
break
|
57
|
+
|
58
|
+
case 2:
|
59
|
+
|
60
|
+
QuestionLabel\.text = "三色の統一ドイツ黒赤金"
|
61
|
+
Button1\.setTitle\("さ", for: \.normal\)
|
62
|
+
|
63
|
+
let synthesizer = AVSpeechSynthesizer\(\)
|
64
|
+
let utterance = AVSpeechUtterance\(string: "三色の統一ドイツ黒赤金"\)
|
65
|
+
synthesizer\.speak\(utterance\)
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
break
|
70
|
+
|
71
|
+
case 3:
|
72
|
+
|
73
|
+
|
74
|
+
QuestionLabel\.text = "エクアドルコンドルが飛ぶアンデスへ"
|
75
|
+
Button1\.setTitle\("え", for: \.normal\)
|
76
|
+
|
77
|
+
let synthesizer = AVSpeechSynthesizer\(\)
|
78
|
+
let utterance = AVSpeechUtterance\(string: "エクアドルコンドルが飛ぶアンデスへ"\)
|
79
|
+
synthesizer\.speak\(utterance\)
|
80
|
+
|
81
|
+
|
82
|
+
break
|
83
|
+
|
84
|
+
//略
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
case 48:
|
89
|
+
|
90
|
+
|
91
|
+
QuestionLabel\.text = "バーレーンはギザギザ模様で鮮やかに"
|
92
|
+
Button1\.setTitle\("ば", for: \.normal\)
|
93
|
+
|
94
|
+
let synthesizer = AVSpeechSynthesizer\(\)
|
95
|
+
let utterance = AVSpeechUtterance\(string: "バーレーンはギザギザ模様で鮮やかに"\)
|
96
|
+
synthesizer\.speak\(utterance\)
|
97
|
+
break
|
98
|
+
|
99
|
+
default:
|
100
|
+
|
101
|
+
break
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
func Hide\(\){
|
108
|
+
|
109
|
+
Next\.isHidden = true
|
110
|
+
}
|
111
|
+
|
112
|
+
func UnHide\(\){
|
113
|
+
|
114
|
+
Next\.isHidden = false
|
115
|
+
}
|
116
|
+
|
117
|
+
@IBAction func Button1Action\(_ sender: AnyObject\) {
|
118
|
+
|
3
|
-
|
119
|
+
UnHide\(\)
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
@IBAction func Next\(_ sender: AnyObject\) {
|
124
|
+
RandomQuestions\(\)
|
125
|
+
}
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
###試したこと
|
134
|
+
nsuser defaultsを使ったり、空の配列を作り一度つかったものを入れたりなどと案は思いつきますが、どのようにコードを書くのかわかりません。
|
3
変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,134 +1,3 @@
|
|
1
|
-
###前提・実現したいこと
|
2
|
-
今カルタの文を読んでくれるアプリ?を作っています。今できているところは48種類のカルタの文をランダムに読んでくれるところです。しかし、一度読んだ文もまた繰り返されます。それを一度読んだものはもう読まないようにしたいです。
|
3
|
-
|
4
|
-
|
5
|
-
ボタンを押すと次の文と最初の文字を表示しその文を
|
6
|
-
読み上げてくれるようになっています。
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
###該当のソースコード
|
12
|
-
|
1
|
+
swift
|
13
|
-
import UIKit
|
14
|
-
|
15
|
-
import AVFoundation
|
16
|
-
|
17
|
-
class ViewController: UIViewController {
|
18
|
-
|
19
|
-
@IBOutlet weak var QuestionLabel: UILabel!
|
20
|
-
|
21
|
-
@IBOutlet weak var Button1: UIButton!
|
22
|
-
|
23
|
-
@IBOutlet weak var Next: UIButton!
|
24
|
-
|
25
|
-
var CorrectAnswer = String()
|
26
|
-
|
27
|
-
override func viewDidLoad() {
|
28
|
-
super.viewDidLoad()
|
29
|
-
|
30
|
-
Hide()
|
31
|
-
RandomQuestions()
|
32
|
-
|
33
|
-
}
|
34
|
-
|
35
|
-
override func didReceiveMemoryWarning() {
|
36
|
-
super.didReceiveMemoryWarning()
|
37
|
-
|
38
|
-
}
|
39
|
-
|
2
|
+
fuiiyiioggggggggggggスィft
|
40
|
-
|
41
|
-
var RandomNumber = arc4random() % 48
|
42
|
-
|
43
|
-
RandomNumber += 1
|
44
|
-
|
45
|
-
switch (RandomNumber) {
|
46
|
-
|
47
|
-
case 1:
|
48
|
-
|
49
|
-
QuestionLabel.text = "モンゴルの民族模様は自由の印"
|
50
|
-
Button1.setTitle("も", for: .normal)
|
51
|
-
//文を読む
|
52
|
-
let synthesizer = AVSpeechSynthesizer()
|
53
|
-
let utterance = AVSpeechUtterance(string: "モンゴルの民族模様は自由の印。")
|
54
|
-
synthesizer.speak(utterance)
|
55
|
-
|
56
|
-
break
|
57
|
-
|
58
|
-
case 2:
|
59
|
-
|
60
|
-
QuestionLabel.text = "三色の統一ドイツ黒赤金"
|
61
|
-
Button1.setTitle("さ", for: .normal)
|
62
|
-
|
63
|
-
let synthesizer = AVSpeechSynthesizer()
|
64
|
-
let utterance = AVSpeechUtterance(string: "三色の統一ドイツ黒赤金")
|
65
|
-
synthesizer.speak(utterance)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
break
|
70
|
-
|
71
|
-
case 3:
|
72
|
-
|
73
|
-
|
74
|
-
QuestionLabel.text = "エクアドルコンドルが飛ぶアンデスへ"
|
75
|
-
Button1.setTitle("え", for: .normal)
|
76
|
-
|
77
|
-
let synthesizer = AVSpeechSynthesizer()
|
78
|
-
let utterance = AVSpeechUtterance(string: "エクアドルコンドルが飛ぶアンデスへ")
|
79
|
-
synthesizer.speak(utterance)
|
80
|
-
|
81
|
-
|
82
|
-
break
|
83
|
-
|
84
|
-
//略
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
case 48:
|
89
|
-
|
90
|
-
|
91
|
-
QuestionLabel.text = "バーレーンはギザギザ模様で鮮やかに"
|
92
|
-
Button1.setTitle("ば", for: .normal)
|
93
|
-
|
94
|
-
let synthesizer = AVSpeechSynthesizer()
|
95
|
-
let utterance = AVSpeechUtterance(string: "バーレーンはギザギザ模様で鮮やかに")
|
96
|
-
synthesizer.speak(utterance)
|
97
|
-
break
|
98
|
-
|
99
|
-
default:
|
100
|
-
|
101
|
-
break
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
}
|
106
|
-
|
107
|
-
|
3
|
+
スィft」えっっっっw
|
108
|
-
|
109
|
-
Next.isHidden = true
|
110
|
-
}
|
111
|
-
|
112
|
-
func UnHide(){
|
113
|
-
|
114
|
-
Next.isHidden = false
|
115
|
-
}
|
116
|
-
|
117
|
-
@IBAction func Button1Action(_ sender: AnyObject) {
|
118
|
-
|
119
|
-
UnHide()
|
120
|
-
|
121
|
-
}
|
122
|
-
|
123
|
-
@IBAction func Next(_ sender: AnyObject) {
|
124
|
-
RandomQuestions()
|
125
|
-
}
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
```
|
132
|
-
|
133
|
-
###試したこと
|
134
|
-
nsuser defaultsを使ったり、空の配列を作り一度つかったものを入れたりなどと案は思いつきますが、どのようにコードを書くのかわかりません。
|
2
コードを直しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -61,7 +61,7 @@
|
|
61
61
|
Button1.setTitle("さ", for: .normal)
|
62
62
|
|
63
63
|
let synthesizer = AVSpeechSynthesizer()
|
64
|
-
let utterance = AVSpeechUtterance(string: "
|
64
|
+
let utterance = AVSpeechUtterance(string: "三色の統一ドイツ黒赤金")
|
65
65
|
synthesizer.speak(utterance)
|
66
66
|
|
67
67
|
|
1
コードを増やしました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,7 +10,32 @@
|
|
10
10
|
|
11
11
|
###該当のソースコード
|
12
12
|
```swift
|
13
|
+
import UIKit
|
14
|
+
|
15
|
+
import AVFoundation
|
16
|
+
|
17
|
+
class ViewController: UIViewController {
|
18
|
+
|
19
|
+
@IBOutlet weak var QuestionLabel: UILabel!
|
13
20
|
|
21
|
+
@IBOutlet weak var Button1: UIButton!
|
22
|
+
|
23
|
+
@IBOutlet weak var Next: UIButton!
|
24
|
+
|
25
|
+
var CorrectAnswer = String()
|
26
|
+
|
27
|
+
override func viewDidLoad() {
|
28
|
+
super.viewDidLoad()
|
29
|
+
|
30
|
+
Hide()
|
31
|
+
RandomQuestions()
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
override func didReceiveMemoryWarning() {
|
36
|
+
super.didReceiveMemoryWarning()
|
37
|
+
|
38
|
+
}
|
14
39
|
func RandomQuestions(){
|
15
40
|
|
16
41
|
var RandomNumber = arc4random() % 48
|
@@ -76,10 +101,33 @@
|
|
76
101
|
break
|
77
102
|
|
78
103
|
}
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
func Hide(){
|
79
108
|
|
109
|
+
Next.isHidden = true
|
110
|
+
}
|
111
|
+
|
112
|
+
func UnHide(){
|
80
113
|
|
114
|
+
Next.isHidden = false
|
115
|
+
}
|
81
116
|
|
117
|
+
@IBAction func Button1Action(_ sender: AnyObject) {
|
118
|
+
|
119
|
+
UnHide()
|
120
|
+
|
121
|
+
}
|
82
122
|
|
123
|
+
@IBAction func Next(_ sender: AnyObject) {
|
124
|
+
RandomQuestions()
|
125
|
+
}
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
|
83
131
|
```
|
84
132
|
|
85
133
|
###試したこと
|