cellを返す処理をセルの中身が入ってから実行したいのですが、Firestoreから情報を取得する処理が完了しないのでできません。どうすればいいでしょうか?
なお、リアルタイムのチャットなので更新があるごとにセルの情報を更新する必要があります
swift
1 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 2 cells = [] 3 if num! == 0{ 4 return 0 5 } 6 a = DispatchSemaphore(value: 0) 7 for i in 0...num!-1 { 8 let cell = tableView.dequeueReusableCell(withIdentifier: "cell") 9 let name = cell?.viewWithTag(1) as! UILabel 10 let message = cell?.viewWithTag(2) as! UILabel 11 let kiki = cell?.viewWithTag(3) as! UILabel 12 let kinum = cell?.viewWithTag(4) as! UILabel 13 ref!.collection("chat").document("(i)").getDocument{document , err in 14 name.text = document?.data()!["name"] as! String 15 message.text = document?.data()!["message"] as! String 16 kinum.text = document?.data()!["kikitai"] as! String 17 if (document?.data()!["username"]as! String) == UserDefaults.standard.string(forKey: "chatroom"){ 18 cell?.backgroundColor = UIColor.yellow 19 kiki.text = "なるほど!" 20 21 }else{ 22 kiki.text = "聞きたい!" 23 } 24 self.cells.append(cell) 25 if i == self.num!-1{ 26 self.a!.signal() 27 } 28 29 } 30 31 } 32 33 return num! 34 } 35 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 36 a!.wait() 37 return cells[indexPath.row]! 38 } 39