回答編集履歴
1
修正と追記
test
CHANGED
@@ -10,9 +10,43 @@
|
|
10
10
|
|
11
11
|
```swift
|
12
12
|
|
13
|
-
|
13
|
+
do {
|
14
14
|
|
15
|
+
let csvStringData = try String(contentsOfFile: csvFilePath, encoding: String.Encoding.utf8)
|
16
|
+
|
17
|
+
// csvデータを1行ずつ読み込む
|
18
|
+
|
19
|
+
csvStringData.enumerateLines ( invoking: {(line, stop) -> () in
|
20
|
+
|
21
|
+
// カンマ区切りで分割
|
22
|
+
|
23
|
+
let questionSourceDataArray = line.components(separatedBy: ",")
|
24
|
+
|
25
|
+
// 問題データを格納するオブジェクトを作成
|
26
|
+
|
27
|
+
let questionData = QuestionData(questionSourceDataArray: questionSourceDataArray)
|
28
|
+
|
29
|
+
// 問題を追加
|
30
|
+
|
31
|
+
self.questionDataArray.append(questionData)
|
32
|
+
|
33
|
+
// 問題番号を設定
|
34
|
+
|
35
|
+
questionData.questionNo = self.questionDataArray.count
|
36
|
+
|
37
|
+
})
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
// シャッフルして最初の3つを取り出す。
|
42
|
+
|
15
|
-
questionArray = Array(questionArray.shuffled().prefix(3))
|
43
|
+
questionDataArray = Array(questionDataArray.shuffled().prefix(3))
|
44
|
+
|
45
|
+
} catch let error {
|
46
|
+
|
47
|
+
...
|
48
|
+
|
49
|
+
|
16
50
|
|
17
51
|
```
|
18
52
|
|
@@ -22,7 +56,7 @@
|
|
22
56
|
|
23
57
|
|
24
58
|
|
25
|
-
すでにquestionArrayがシャッフルされて3問だけになっているので、
|
59
|
+
すでにquestionDataArrayがシャッフルされて3問だけになっているので、
|
26
60
|
|
27
61
|
```swift
|
28
62
|
|
@@ -30,7 +64,7 @@
|
|
30
64
|
|
31
65
|
|
32
66
|
|
33
|
-
return questionArray.popLast()
|
67
|
+
return questionDataArray.popLast()
|
34
68
|
|
35
69
|
}
|
36
70
|
|