質問編集履歴

2

Modelの中身を更新(違うModelを記載してしまっていました。)

2021/11/25 02:23

投稿

ishiishiyay
ishiishiyay

スコア33

test CHANGED
File without changes
test CHANGED
@@ -126,127 +126,103 @@
126
126
 
127
127
 
128
128
 
129
- struct User: Identifiable, Decodable {
130
-
131
-
132
-
133
- let id: Int
134
-
135
-
136
-
137
- let usersSchool: String
138
-
139
- let usersAccount: String
140
-
141
- let usersBirthday: String
142
-
143
- let usersNumberLastFour: String
144
-
145
- let usersImageUrl: String
146
-
147
- let usersThumbnailImageUrl: String
148
-
149
- let usersName: String
150
-
151
- let usersProfileText: String
152
-
153
-
154
-
155
- let isPublicUsersName: Bool
156
-
157
- let isPublicUsersPage: Bool
158
-
159
-
160
-
161
- var isFriend = false
162
-
163
- var isSentFriendRequest = false
164
-
165
- var isReceivedFriendRequest = false
166
-
167
- var isSentBlocks = false
168
-
169
-
170
-
171
-
172
-
173
- enum CodingKeys: String, CodingKey {
174
-
175
- case id = "users_id"
176
-
177
-
178
-
179
- case usersSchool = "users_school"
180
-
181
- case usersAccount = "users_account"
182
-
183
- case usersBirthday = "users_birthday"
184
-
185
- case usersNumberLastFour = "users_number_last_four"
186
-
187
- case usersImageUrl = "users_image_url"
188
-
189
- case usersThumbnailImageUrl = "users_thumbnail_image_url"
190
-
191
- case usersName = "users_name"
192
-
193
- case usersProfileText = "users_profile_text"
194
-
195
-
196
-
197
- case isPublicUsersName = "is_public_users_name"
198
-
199
- case isPublicUsersPage = "is_public_users_page"
200
-
201
-
202
-
203
- case isFriend = "is_friend"
204
-
205
- case isSentFriendRequest = "is_sent_friend_request"
206
-
207
- case isReceivedFriendRequest = "is_received_friend_request"
208
-
209
- case isSentBlocks = "is_sent_blocks"
210
-
211
-
129
+ struct FriendsRequestsList: Identifiable, Decodable {
130
+
131
+
132
+
133
+ let id: Int
134
+
135
+ let numberOfFriendsRequests: Int
136
+
137
+ let friendsRequests: [FriendsRequests]
138
+
139
+
140
+
141
+
142
+
143
+ enum CodingKeys: String, CodingKey {
144
+
145
+ case id = "users_id"
146
+
147
+ case numberOfFriendsRequests = "number_of_friends_requests"
148
+
149
+ case friendsRequests = "friends_requests"
150
+
151
+ }
152
+
153
+
154
+
155
+ init(from decoder: Decoder) throws {
156
+
157
+
158
+
159
+ let container = try decoder.container(keyedBy: CodingKeys.self)
160
+
161
+
162
+
163
+ self.id = try container.decodeIfPresent(Int.self, forKey: .id) ?? 0
164
+
165
+ self.numberOfFriendsRequests = try container.decodeIfPresent(Int.self, forKey: .numberOfFriendsRequests) ?? 0
166
+
167
+ self.friendsRequests = try container.decodeIfPresent([FriendsRequests].self, forKey: .friendsRequests) ?? [FriendsRequests]()
168
+
169
+
212
170
 
213
171
  }
214
172
 
215
-
216
-
217
- init(from decoder: Decoder) throws {
173
+
218
-
219
-
220
-
221
- let container = try decoder.container(keyedBy: CodingKeys.self)
222
-
223
-
224
-
225
- self.id = try container.decodeIfPresent(Int.self, forKey: .id) ?? 0
226
-
227
- self.usersSchool = try container.decodeIfPresent(String.self, forKey: .usersSchool) ?? ""
228
-
229
- self.usersAccount = try container.decodeIfPresent(String.self, forKey: .usersAccount) ?? ""
230
-
231
- self.usersBirthday = try container.decodeIfPresent(String.self, forKey: .usersBirthday) ?? ""
232
-
233
- self.usersNumberLastFour = try container.decodeIfPresent(String.self, forKey: .usersNumberLastFour) ?? ""
234
-
235
- self.usersImageUrl = try container.decodeIfPresent(String.self, forKey: .usersImageUrl) ?? ""
236
-
237
- self.usersThumbnailImageUrl = try container.decodeIfPresent(String.self, forKey: .usersThumbnailImageUrl) ?? ""
238
-
239
- self.usersName = try container.decodeIfPresent(String.self, forKey: .usersName) ?? ""
240
-
241
- self.usersProfileText = try container.decodeIfPresent(String.self, forKey: .usersProfileText) ?? ""
242
-
243
- self.isPublicUsersName = try container.decodeIfPresent(Bool.self, forKey: .isPublicUsersName) ?? false
244
-
245
- self.isPublicUsersPage = try container.decodeIfPresent(Bool.self, forKey: .isPublicUsersPage) ?? false
246
174
 
247
175
  }
248
176
 
177
+
178
+
179
+ struct FriendsRequests: Identifiable, Decodable {
180
+
181
+ let id: Int
182
+
183
+ let usersName: String
184
+
185
+ let usersThumbnailImageUrl: String
186
+
187
+
188
+
189
+
190
+
191
+ enum CodingKeys: String, CodingKey {
192
+
193
+ case id = "users_id"
194
+
195
+ case usersName = "users_name"
196
+
197
+ case usersThumbnailImageUrl = "users_thumbnail_image_url"
198
+
249
- }
199
+ }
200
+
201
+
202
+
203
+ init(from decoder: Decoder) throws {
204
+
205
+
206
+
207
+ let container = try decoder.container(keyedBy: CodingKeys.self)
208
+
209
+
210
+
211
+ self.id = try container.decodeIfPresent(Int.self, forKey: .id) ?? 0
212
+
213
+ self.usersName = try container.decodeIfPresent(String.self, forKey: .usersName) ?? ""
214
+
215
+ self.usersThumbnailImageUrl = try container.decodeIfPresent(String.self, forKey: .usersThumbnailImageUrl) ?? ""
216
+
217
+
218
+
219
+ }
220
+
221
+
222
+
223
+
224
+
225
+ }
250
226
 
251
227
  ```
252
228
 

1

細かい修正

2021/11/25 02:23

投稿

ishiishiyay
ishiishiyay

スコア33

test CHANGED
File without changes
test CHANGED
@@ -6,9 +6,9 @@
6
6
 
7
7
  サーバーからJSONデータ(自分に来た友達申請情報)を取得し、辞書に格納したあと、
8
8
 
9
- xx秒おきにサーバーを監視し、もし新たに友達申請が増えていた場合に
9
+ xx秒おきにサーバーを監視し(サーバー監視のロジックは省略させくださ
10
-
10
+
11
- その更新分を取得し、辞書に追加したいと考えています。
11
+ もし新たに友達申請が増えていた場合に、その更新分を取得し、辞書に追加したいと考えています。
12
12
 
13
13
 
14
14