質問編集履歴

1

回答を受けて追記

2019/12/16 10:17

投稿

RyotaroIsoyama
RyotaroIsoyama

スコア183

test CHANGED
File without changes
test CHANGED
@@ -121,3 +121,81 @@
121
121
 
122
122
 
123
123
  ご教授いただきたいです。また、何か情報が足りなければお申し付けください。
124
+
125
+
126
+
127
+ ### 追記
128
+
129
+ ```swift
130
+
131
+ // セルを返す
132
+
133
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
134
+
135
+ let cell = tableView.dequeueReusableCell(withIdentifier: "SocialTableViewCell", for: indexPath) as! SocialTableViewCell
136
+
137
+ let queue = DispatchQueue.global(qos: .default)
138
+
139
+ let dataset = self.fetchSocialTable()
140
+
141
+ queue.async {
142
+
143
+ cell.UserName.text = dataset[indexPath.row].UserName
144
+
145
+ cell.UserID.text = dataset[indexPath.row].UserID
146
+
147
+ }
148
+
149
+
150
+
151
+ return cell
152
+
153
+ }
154
+
155
+
156
+
157
+ func fetchSocialTable() -> [SocialTable]{
158
+
159
+ let semaphore = DispatchSemaphore(value: 0)
160
+
161
+ var data:[SocialTable] = []
162
+
163
+ self.db.collection("users").document(self.uid).collection("followers").limit(to:20).getDocuments(){snapshot,err in
164
+
165
+ if let snapshot = snapshot{
166
+
167
+ print("connect firestore...")
168
+
169
+ for document in snapshot.documents {
170
+
171
+ data.append(SocialTable(iconname: "hogehoge", UserName: document.data()["Nm"] as! String, UserID: document.data()["UI"] as! String))
172
+
173
+ }
174
+
175
+ }
176
+
177
+ semaphore.signal()
178
+
179
+ print("semaphore ok")
180
+
181
+ print(self.socialTable)
182
+
183
+ }
184
+
185
+ print("semaphore wait...")
186
+
187
+ semaphore.wait()
188
+
189
+ print("complete...")
190
+
191
+ return data
192
+
193
+ }
194
+
195
+ ```
196
+
197
+ これで実行した場合、semaphore wait...のみが出力されその後の処理が走りません。
198
+
199
+ 一旦テーブルへの書き込みをやめて、firestoreからデータを取得する部分の確認を行ったのですが、それは上手くいっていました。
200
+
201
+ 何かいけない点があるのでしょうか。