【发布时间】:2017-03-08 03:17:10
【问题描述】:
所以我目前正在尝试从我的 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
}
}
}
}
}
【问题讨论】:
标签: ios arrays swift firebase firebase-realtime-database