gpt4 book ai didi

ios - 如何检索某些 childByAutoId() 键

转载 作者:行者123 更新时间:2023-11-28 06:15:03 25 4
gpt4 key购买 nike

我环顾四周,没有运气。我需要在 firebase 中获取某个字典键的字符串值。

如果你看下面的图片,我需要那个键在上面,并且需要将它设置为一个字符串,这样我就可以连接到其他 View Controller ,所以当用户想要在共享者下发帖时,例如,我根据 key 进入正确的值,然后到共享者,我可以在其中添加值。谢谢,我也不需要所有值,一旦我观察到 WithSingleEvent,我就需要获取每个页面或字典的键。

enter image description here

我的代码:

    let ref = FIRDatabase.database().reference()
ref.child("Notes").queryOrderedByKey().observeSingleEvent(of: .value, with: { snapshot in
if let pagers = snapshot.value as? [String : AnyObject] {
let numb = snapshot.key //what I want
for (_, val) in pagers {
if let useri = val["postUsername"] as? String {
if useri == FIRAuth.auth()?.currentUser?.uid {

let bindfl = Page()
if let title = val["title"] as? String, let descript = val["description"] as? String,
let sharers = val["sharers"] as? [String], let poster = val["postUsername"] as? String, let setter = val["setter"] as? String, let creatorName = val["creatorName"] as? String {
bindfl.title = title
bindfl.descriptions = descript
bindfl.setter = setter
bindfl.sharers = sharers
bindfl.usernameOfBinder = poster
bindfl.creatorName = creatorName
bindfl.theBit = numb

self.pages.append(bindfl)

最佳答案

当你向数据库中添加数据时,你可以这样做

let key = ref.("Notes").childByAutoId().key
let notes = ["userName": userName,
"description": description,
"title": title,
"author": author,
"keyID": key]
let childUpdates = ["/Notes/\(key)": notes]
ref.updateChildValues(childUpdates)

之后就可以了,这样获取key

bindfl.title = title
bindfl.descriptions = descriptions
bindfl.userName = userName
bindfl.author= author
bindfl.keyID= keyID

希望它有用。

关于ios - 如何检索某些 childByAutoId() 键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45404350/

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