gpt4 book ai didi

ios - 使用阵列 SWIFT 从 child 那里接收 Firebase 快照

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

所以我目前正在尝试从我的 Firebase 数据库中获取数据并将其设置为自己的变量,但每个图表的子项都是特定的日期和时间 (yy.mm.dd.h.m.s)。所以我有一个数组存储我需要的所有日期,但在调用我的快照时我无法引用它们。我已经尝试了这两种抛出错误的方法 "(child:) Must be a non-empty string and not contain '.' '#' '$' '[' 或 ']''"

var postCollection = [170802120618, 170802101427] //yy.mm.dd.hh.mm.ss   

ref.child("users").child(uid!).child("Posts").child(self.postCollection[indexPath.row]).observe(.value, with: { (snapshot) in
for item in snapshot.children{
let snapshotValue = snapshot.value as? NSDictionary
let firstNameSnap = snapshotValue?["First Name"] as? String ?? ""
currentCell.nameLabel.text = firstNameSnap
}
})

var postCollection = [170802120618, 170802101427]  //yy.mm.dd.hh.mm.ss  
let selection = self.postCollection[indexPath.row]
ref.child("users").child(uid!).child("Posts").child(self.postCollection[indexPath).observe(.value, with: { (snapshot) in
for item in snapshot.children{
let snapshotValue = snapshot.value as? NSDictionary
let firstNameSnap = snapshotValue?["First Name"] as? String ?? ""
currentCell.nameLabel.text = firstNameSnap
}
})

数据库图表大致如下:

FIR{
users{
uid{
username: UserName
Posts{
170802120618{
First Name: first
}
}
}
}
}

最佳答案

没错。您希望子键是自动生成的哈希值。您可以使用 childByAutoId() 创建它们。另外,如果我是你,我只会将日期存储为字符串并根据需要解析它们。下面是一个例子:

Posts {
-Kebfdajksthm {
first_name: "first",
post_date: "yymmddhhmmss"
}
}

关于ios - 使用阵列 SWIFT 从 child 那里接收 Firebase 快照,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42662337/

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