【发布时间】:2017-02-10 19:39:35
【问题描述】:
我有数据库“通知”。
{
"Notification": {
"user_id":
"date":
"type":
"info": {
"who_id":
"whom_id":
}
}
}
当我第一次启动应用程序时,我会从“通知”中获取并获取所有数据。当我向“通知”添加新数据时,我获取的数据没有“信息”字段。只有字段:日期、类型、user_id。
我的代码:
func fetchNotitfications() {
FIRDatabase.database().reference().child("Notification").queryOrdered(byChild: "user_id").queryEqual(toValue: FIRAuth.auth()?.currentUser?.uid).observe(.childAdded, with: { (snapshot) in
if let notificationDict = snapshot.value as? [String:AnyObject] {
let notification = Notification()
notification.setValuesForKeys(notificationDict)
self.notificationTableView.arrayNotification.append(notification)
self.notificationTableView.reloadData()
}
})
}
【问题讨论】:
-
请将您的 Firebase 结构发布为文本,而不是图像。文本是可搜索的,图像不是,当我们提供一个简洁的答案时,我们需要能够复制和粘贴您的结构,而我们不能用图像来做到这一点。
-
我想如果你在你的闭包中添加一个快速的print(snapshot),你可能会发现一些有趣的数据。另一个注意事项;请记住,当您使用 .childAdded 时,它将迭代并返回所有符合条件的子节点,并再次为添加的任何符合条件的新节点返回该数据。
标签: ios swift firebase firebase-realtime-database