質問編集履歴

2

記述の追加をしました

2020/04/20 09:00

投稿

rainyeveryday
rainyeveryday

スコア22

test CHANGED
File without changes
test CHANGED
@@ -26,9 +26,37 @@
26
26
 
27
27
 
28
28
 
29
+ import Foundation
30
+
31
+ import Alamofire
32
+
33
+
34
+
35
+ class GetData {
36
+
37
+
38
+
39
+ var youtubeData:YoutubeData?
40
+
41
+ var publishedAtArray:[String]?
42
+
43
+ var titleArray:[String]?
44
+
45
+ var imageURLStringArray:[String]?
46
+
47
+ var youtubeURLArray:[String]?
48
+
49
+ var channelTitleArray:[String]?
50
+
51
+ var videoIdArray:[String]?
52
+
53
+
54
+
55
+
56
+
29
57
  init(urlText: String){
30
58
 
31
-
59
+
32
60
 
33
61
  let text = urlText
34
62
 
@@ -41,6 +69,8 @@
41
69
 
42
70
 
43
71
  print(response)
72
+
73
+
44
74
 
45
75
  switch response.result {
46
76
 
@@ -66,7 +96,9 @@
66
96
 
67
97
  let youtubeURL = "https://www.youtube.com/watch?v=(videoId)"
68
98
 
69
- let channelTitle = json["items"][i]["snippet"]["channelTitle"].string
99
+ let channelTitle = json["items"][i]["snippet"]["channelTitle"].string
100
+
101
+
70
102
 
71
103
  self.videoIdArray.append(videoId)
72
104
 
@@ -80,7 +112,9 @@
80
112
 
81
113
  self.channelTitleArray.append(channelTitle)
82
114
 
115
+
116
+
83
- }
117
+ }
84
118
 
85
119
  break
86
120
 
@@ -96,10 +130,50 @@
96
130
 
97
131
  self.tableView.reloadData()
98
132
 
133
+
134
+
99
- }
135
+ }
100
136
 
101
137
 
102
138
 
103
139
 
104
140
 
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+ }
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+ }
172
+
173
+
174
+
175
+
176
+
177
+
178
+
105
179
  ```

1

メソッドを追加しました

2020/04/20 09:00

投稿

rainyeveryday
rainyeveryday

スコア22

test CHANGED
File without changes
test CHANGED
@@ -17,3 +17,89 @@
17
17
 
18
18
 
19
19
  どのようにすれば値を渡せるのでしょうか。ご教授お願いします。
20
+
21
+
22
+
23
+ GetDataのメソッドは以下のとおりです。
24
+
25
+ ```Swift
26
+
27
+
28
+
29
+ init(urlText: String){
30
+
31
+
32
+
33
+ let text = urlText
34
+
35
+ let url = text.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
36
+
37
+
38
+
39
+ AF.request(url as! URLConvertible, method: .get, parameters: nil, encoder: JSONEncoding.default as! ParameterEncoder){ (response) in
40
+
41
+
42
+
43
+ print(response)
44
+
45
+ switch response.result {
46
+
47
+ case .success:
48
+
49
+
50
+
51
+ for i in 0...39 {
52
+
53
+
54
+
55
+ let json: JSON = JSON(response.data as Any)
56
+
57
+ let videoId = json["items"][i]["id"]["videoId"].string
58
+
59
+ let publishedAt = json["items"][i]["snippet"]["publishedAt"].string
60
+
61
+ let title = json["items"][i]["snippet"]["title"].string
62
+
63
+ let imageURLString = json["items"][i]["snippet"]["thumbnails"]["default"]["url"].string
64
+
65
+
66
+
67
+ let youtubeURL = "https://www.youtube.com/watch?v=(videoId)"
68
+
69
+ let channelTitle = json["items"][i]["snippet"]["channelTitle"].string
70
+
71
+ self.videoIdArray.append(videoId)
72
+
73
+ self.publishedAtArray.append(publishedAt)
74
+
75
+ self.titleArray.append(title)
76
+
77
+ self.imageURLStringArray.append(imageURLString)
78
+
79
+ self.youtubeURLArray.append(youtubeURL)
80
+
81
+ self.channelTitleArray.append(channelTitle)
82
+
83
+ }
84
+
85
+ break
86
+
87
+ case .failure(let error):
88
+
89
+ print(error)
90
+
91
+ break
92
+
93
+ }
94
+
95
+
96
+
97
+ self.tableView.reloadData()
98
+
99
+ }
100
+
101
+
102
+
103
+
104
+
105
+ ```