作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用具有以下结构的 Firebase:
当我单击“保存”按钮时,这是写入 firebase 的代码:
let savedDB = Database.database().reference().child("saved")
let postid = detailpost?.postid
let uid = Auth.auth().currentUser?.uid
let key = savedDB.child(postid!).key
let childUpdates : [String : String] = ["\(uid!)/\(key)/": "true"]
savedDB.updateChildValues(childUpdates)
要尝试读取数据,这是我的代码:
if let uid = Auth.auth().currentUser?.uid{
let savedDB = Database.database().reference().child("saved").child(uid)
savedDB.observe(.childAdded) { (snapshot) in
let snapshotValue = snapshot.value as! Dictionary<String,String>
if let savedpostid = snapshotValue["postid"]{
......
当我的代码到达这一步时,它崩溃了,并显示以下错误消息:
Could not cast value of type 'NSTaggedPointerString' (0x111688e88) to 'NSDictionary' (0x1116891a8).
我无法弄清楚导致此问题的原因以及如何解决它。有人可以建议吗?谢谢。
最佳答案
更改此:
let snapshotValue = snapshot.value as! Dictionary<String,String>
进入此:
let snapshotValue = snapshot.value as! FIRDataSnapshot
查看此链接以获取更多信息:https://firebase.google.com/docs/reference/ios/firebasedatabase/api/reference/Classes/FIRDataSnapshot
A FIRDataSnapshot contains data from a Firebase Database location. Any time you read Firebase data, you receive the data as a FIRDataSnapshot.
关于ios - 如何解决这个: "Could not cast value of type ' NSTaggedPointerString' (0x105d25e88) to 'NSDictionary' (0x105d261a8).”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48477386/
我是一名优秀的程序员,十分优秀!