gpt4 book ai didi

swift 从 firebase 检索快照节点的最佳方法是什么

转载 作者:行者123 更新时间:2023-11-28 16:11:07 26 4
gpt4 key购买 nike

如何从此快照中检索 senderIdChildAdded 必须使用并且下面的 FirRef 必须保持不变。

这是我当前从 firebase 检索数据的函数

 func retrieveInfo(completion: (result: String)->()) {
fireBaseAPI().childRef("version_one/frontEnd/post/\(self.previousViewMessageId)").observeEventType(.ChildAdded, withBlock: {snapshot in



})

这是正在打印的快照

Snap (postDescription) Description here
Snap (postTitle) What do you need done
Snap (receiverId) RYclS9Qy4vRr6gp8JbfoztSYQnL2
Snap (senderId) niZKOcnoh0cdFpF2K26bxugw1hz1
Snap (status) 0
Snap (messages) {
"-KRqOqd2POJYpCNSSumG" = {
mediaType = TEXT;
senderDisplayName = "";
senderId = niZKOcnoh0cdFpF2K26bxugw1hz1;
text = iPhone;
};
}

检索任何显示 Snap 的节点的最佳方法是什么

这是 Firebase Json

 {
"version_one" : {
"frontEnd" : {
"post" : {
"-KRoucvwAs1jBaoNahDP" : {
"messages" : {
"-KRqOqd2POJYpCNSSumG" : {
"mediaType" : "TEXT",
"senderDisplayName" : "",
"senderId" : "niZKOcnoh0cdFpF2K26bxugw1hz1",
"text" : "iPhone"
}
},
"postDescription" : "Description here",
"postTitle" : "What do you need done",
"receiverId" : "RYclS9Qy4vRr6gp8JbfoztSYQnL2",
"senderId" : "niZKOcnoh0cdFpF2K26bxugw1hz1",
"status" : 0
}
},

最佳答案

func retrieveInfo(completion: (result: String)->()) {
fireBaseAPI().childRef("version_one/frontEnd/post/\(self.previousViewMessageId)").observeEventType(.ChildAdded, withBlock: {snapshot in
if let messageDict = snapshot.value in [String:AnyObject]{

let senderId = messageDict["senderId"] as! String
.....


}

})

关于swift 从 firebase 检索快照节点的最佳方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39542912/

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