【发布时间】:2018-06-12 06:44:51
【问题描述】:
这是我的 Firebase 树的快速输出,id 喜欢访问 people_on_this_planit / userID 节点。我唯一的问题是该节点在自动 ID 内;请任何帮助将不胜感激。谢谢
planits
-LEmgxuG_13KNA5inRaB
Planit Title: "Some title"
people_on_planit
-LEmh6IxqguVBJEwghZv (auto ID)
userID: "kkdiEW0D9"
senderId: "39FdLfdIO8832"
现在我使用的代码如下,但是当我打印 peopleonplanit 时我得到了 nil。
ref = Database.database().reference()
let userID = Auth.auth().currentUser?.uid
let planitsRef = ref.child("planits")
for child in snapshot.children {
let childSnap = child as! DataSnapshot
let dict = childSnap.value as! NSDictionary
let planKey = childSnap.key
//print(planKey)
print(dict)
let title = dict["Planit Title"] as! String
let senderID = dict["senderId"] as! String
let peopleOnPlanit = dict["people_on_planit"] as? String
print(peopleOnPlanit)
}
【问题讨论】:
-
好的。回答一个问题:你认为键
"people_on_planit"中的value是String吗? 它又是一本字典。并且不要在swift中使用NS前缀类型 -
哦,是的,哇,我知道我的错误在哪里了。我将其视为字符串而不是字典。哇。谢谢
-
swift 让我在这里使用 NSDictionary。使用普通字典我得到一个错误
-
你用什么代替了
NSDictionary? -
我试着只放字典