将数据分配给Firebase中的变量

时间:2019-07-01 20:18:40

标签: swift firebase firebase-realtime-database

我正在尝试将Firebase中的数据分配给变量,但是当我将变量打印到控制台时,该值为nil。这是代码和输出的屏幕截图 http://www.simpleimageresizer.com/_uploads/photos/2a10c27a/Screen_Shot_2019-07-01_at_1.11.37_PM_50.png

let ref=Database.database().reference()
//gets information of specific user based on id and assigns their info to the user object
var userDatabase=ref.child("users/userId/\(userId)").observe(.childAdded, with:{(snapshot) in
    print(snapshot)
    let data=snapshot.value as? [String:Any]
    let currentWeight=data?["currentWeight"] as? String
    print(currentWeight)

{   “ currentWeight”:145,   “ gender”:“男”,   “身高”:68,   “ name”:“ Courtney”,   “ targetWeight”:150 }

0 个答案:

没有答案