質問編集履歴

2

コードを全部載せました。ただ、APIの部分は一部隠してあります。よろしくお願いします。

2021/05/01 13:02

投稿

animal_anny
animal_anny

スコア4

test CHANGED
File without changes
test CHANGED
@@ -8,33 +8,19 @@
8
8
 
9
9
  ### 発生している問題・エラーメッセージ
10
10
 
11
- ・Contextual closure type '() -> some View' expects 0 arguments, but 1 was used in closure body
11
+
12
-
13
-
14
-
15
- ・Generic parameter 'SelectionValue' could not be inferred
12
+
16
-
17
- Explicitly specify the generic arguments to fix this issue
18
-
19
-
20
-
21
- ・Missing argument label 'selection:' in call
22
-
23
- Insert 'selection: '
24
-
25
-
26
-
27
- ・Referencing subscript 'subscript(dynamicMember:)' requires wrapper 'ObservedObject<getDate>.Wrapper'
28
-
29
- Insert '$'
30
-
31
-
32
-
33
- ・Value of type 'getDate' has no dynamic member 'datas' using key path from root type 'getDate'
34
-
35
- ```
13
+ ```
36
-
14
+
37
- エラーメッセージ
15
+ Cannot find 'getData' in scope
16
+
17
+ The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
18
+
19
+ Cannot find 'ContentView' in scope
20
+
21
+ Contextual closure type '(Data?, URLResponse?, Error?) -> Void' expects 3 arguments, but 2 were used in closure body
22
+
23
+ Consecutive statements on a line must be separated by ';'
38
24
 
39
25
  ```
40
26
 

1

コードを全部載せました。ただ、APIの部分は一部隠してあります。よろしくお願いします。

2021/05/01 13:02

投稿

animal_anny
animal_anny

スコア4

test CHANGED
File without changes
test CHANGED
@@ -42,11 +42,23 @@
42
42
 
43
43
  ### 該当のソースコード
44
44
 
45
+
46
+
47
+ ```
48
+
49
+ import SwiftUI
50
+
51
+ import SwiftyJSON
52
+
53
+ import SDWebImageSwiftUI
54
+
55
+
56
+
45
- struct ContentView: View {
57
+ struct CotentView: View {
46
-
47
-
48
-
58
+
59
+
60
+
49
- @ObservedObject var list = getDate()
61
+ @ObservedObject var list = getData()
50
62
 
51
63
 
52
64
 
@@ -94,9 +106,117 @@
94
106
 
95
107
  }
96
108
 
109
+ struct ContentView_Previews: PreviewProvider {
110
+
111
+ static var previews: some View {
112
+
97
- ```ここに言語名を入力
113
+ ContentView()
114
+
98
-
115
+ }
116
+
117
+ }
118
+
119
+
120
+
121
+ struct detaType : Identifiable {
122
+
123
+
124
+
125
+ var id : String
126
+
127
+ var title : String
128
+
129
+ var desc : String
130
+
131
+ var url : String
132
+
133
+ var image : String
134
+
135
+
136
+
137
+ }
138
+
139
+
140
+
141
+ class getDate : ObservableObject{
142
+
143
+
144
+
145
+ @Published var detas = [detaType]()
146
+
147
+
148
+
149
+ init() {
150
+
151
+
152
+
153
+ let source = "https://newsapi.org/v2/top-headlines?country=us&category=business&apiKey"
154
+
155
+
156
+
157
+ let url = URL(string: source)!
158
+
159
+
160
+
161
+ let session = URLSession(configuration: .default)
162
+
163
+
164
+
165
+ session.dataTask(with: url) { (data, , err) in
166
+
167
+
168
+
169
+ if err != nil{
170
+
171
+ print((err?.localizedDescription)!)
172
+
99
- ソースコード
173
+ return
174
+
175
+ }
176
+
177
+
178
+
179
+ let json = try! JSON(data: data!)
180
+
181
+
182
+
183
+ for i in json["articles"]{
184
+
185
+
186
+
187
+ let title = i.1["title"].stringValue
188
+
189
+ let description = i.1["description"].stringValue
190
+
191
+ let url = i.1["url"].stringValue
192
+
193
+ let image = i.1["urlToImage"].stringValue
194
+
195
+ let id = i.1["publishedAT"].stringValue
196
+
197
+ DispatchQueue.main.async {
198
+
199
+
200
+
201
+ self.datas.append(dataType(id: id, title: title, desc: description, url:url, image: image ))
202
+
203
+
204
+
205
+ }
206
+
207
+
208
+
209
+ self.datas.append(dataType(id: id, title: title, desc: description, url:url, image: image ))
210
+
211
+
212
+
213
+ }.resume()
214
+
215
+
216
+
217
+
218
+
219
+ }
100
220
 
101
221
  ```
102
222