【发布时间】:2020-06-28 22:25:14
【问题描述】:
我正在尝试从我的 Firebase 数据库中获取用户,在 UITableView 上显示他们的姓名并能够搜索他们。出于某种原因,我在此函数中看到两个错误以获取用户。
- 错误:'user' 类型的值在'self.users.append(user)' 行没有成员'append'
- 错误:没有“dispatch_get_main_queue”候选者在“dispatch_async(dispatch_get_main_queue)”行产生预期的上下文结果类型“(DispatchQueue, () -> Void)”
如果您知道任何解决此问题的方法,请告诉我。我已经坚持了一段时间,似乎无法让用户显示。谢谢。
func fetchUser() {
Database.database().reference().child("users").observe(.childAdded, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
let user = User()
//will crash if your class properties don't exactly match up with firebase dictionary keys
user.setValuesForKeys(dictionary)
self.users.append(user)
//this will crash because of background thread, so use dispatch async to fix
dispatch_async(dispatch_get_main_queue)
self.tableView.reloadData()
print(user.name!, user.email!)
【问题讨论】:
-
我昨天已经就你的问题评论了这个确切的问题:stackoverflow.com/questions/62616575/…。将来如果评论不清楚,请回复它而不是重新发布相同的问题。
-
很抱歉,感谢您昨天的回复。该帖子已被关闭,因为它的格式不正确,我没有看到您的回复。我的坏,新来的。再次感谢您的回答
标签: ios swift database firebase