iOS - Firebase 返回 null 但包含数据的字段存在
<p><p>我有数据库“通知”。</p>
<pre><code>{
"Notification": {
"user_id":
"date":
"type":
"info": {
"who_id":
"whom_id":
}
}
}
</code></pre>
<p>当我第一次启动应用程序时,我会从“通知”获取所有数据。当我将新数据添加到“通知”时,我获取的数据没有“信息”字段。只有字段:日期、类型、user_id。 </p>
<p>我的代码:</p>
<pre><code>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? {
let notification = Notification()
notification.setValuesForKeys(notificationDict)
self.notificationTableView.arrayNotification.append(notification)
self.notificationTableView.reloadData()
}
})
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>当您使用 childadded 时,返回的快照与您预期的不同。 </p>
<p>而不是得到`</p>
<pre><code>"Notification": {
"user_id":
"date":
"type":
"info": {
"who_id":
"whom_id":
}
}
</code></pre>
<p>根据查询过滤数据的方式,您很可能会得到以下结果。</p>
<pre><code>["user_id":
"date":
"type":
"info": {
"who_id":
"whom_id":
}
]
</code></pre></p>
<p style="font-size: 20px;">关于iOS - Firebase 返回 null 但包含数据的字段存在,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/42167395/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/42167395/
</a>
</p>
页:
[1]