gpt4 book ai didi

ios - 如何解决这个: "Could not cast value of type ' NSTaggedPointerString' (0x105d25e88) to 'NSDictionary' (0x105d261a8).”

转载 作者:行者123 更新时间:2023-11-30 11:49:32 25 4
gpt4 key购买 nike

我正在使用具有以下结构的 Firebase:

firebase structure here

当我单击“保存”按钮时,这是写入 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com