Firebase Swift 3.0数据读取解包问题

时间:2016-10-14 19:46:29

标签: firebase

dbRef.observe(.value, with: { (snapshot: FIRDataSnapshot in
     for thingy in snapshot.children {
       let thingyFinal = thingy as? FIRDataSnapshot
         print(thingyFinal)
}})

我的数据库结构如下:

->mung-37e2c: { "users": { "kimkardashian": "stuff", "donaldtrump": "stuff" }, goals: { "goal1" : "stuff", "goal2" : "stuff" } }

我无法解决的问题是错误是由我的代码的第一行触发的:

dbRef.observe(.value, with: { (snapshot: FIRDataSnapshot in

由于我在这里没有强行解包,为什么会触发解缠错误。此外,数据库没有nil值。

1 个答案:

答案 0 :(得分:1)

尝试将代码更改为: -

FIRDatabase.database().reference().observe(.value, with: { (snapshot: FIRDataSnapshot) in
 for thingy in snapshot.children {
   let thingyFinal = thingy as? FIRDataSnapshot
     print(thingyFinal)
   }
})