swift - 使用 firebase 更新值
问题描述
我有一个 firebase ref,我想更新 firebase 的 ref,但是当我尝试它时,我的应用程序崩溃了Could not cast value of type '__NSCFBoolean' (0x2106be078) to 'NSDictionary'
我的参考如下所示
Database.database().reference(forLastMsg: championId).child(toID).updateChildValues(withValues)
Database.database().reference(forLastMsg: toID).child(championId).updateChildValues(withValues)
即使使用setValue
也会使应用程序崩溃。
实际上,我一直在不断地聆听更新的参考文献,例如 valueChange
for snapshot in snapshot.children {
let receivedMessage = (snapshot as! DataSnapshot).value as!
NSDictionary
...
解决方案
你必须以这种方式更新它
let updateDatabase = databaseReference.child("something").child(someId)
let data = [
"boolValue": myBoolean,
"dateUpdated": Date().toSeconds()
] as [String : Any]
updateDatabase.updateChildValues(data)
推荐阅读
- python - Python - 将一张图片粘贴到另一张图片上
- python - 从另一个子文件夹导入一个类
- linux - /usr/bin/ld: 找不到 -lpq 问题
- ios - SwiftUI ScrollView 使用 .id() 滚动过去的元素
- c# - 如何在 F# 中使用 Xamarin.Forms.Maps 创建自定义事件?
- mobx - 在 mobx 模型中我应该为 RouterStore 设置哪种类型?
- vb.net - 如何声明全局变量并在函数中使用它们 [Visual Basic]
- python - Pandas 如果列包含字符串,则从另一列获取唯一值并从数据框中删除行
- python - psycopg2 不能用 docker 安装
- python - 在 Numpy 中对每次操作的浮点精度进行基准测试