简体   繁体   English

Firebase Real Database数据获取

[英]Firebase Real Database data fetching

I am trying the get the following values as variables 我正在尝试获取以下值作为变量

在此处输入图片说明

But my code gives me nil 但是我的代码给了我零

ref.child("users").child(userID!).observeSingleEvent(of: .value, with: { (snapshot) in
    // Get user value
    let value = snapshot.value as? NSDictionary
    let userInfo = value?["UserInfo"] as? NSDictionary
    let data = userInfo?["lat"] as? String ?? ""
    print(data)


    // ...
}) { (error) in
    print(error.localizedDescription)
}

ًWhat am I missing ? missing我想念什么?

You have just to do a small change here: 您只需在这里做一个小改动:

let data = userInfo?["lat"] as? String ?? ""

Latitude is not a String, but an Int, so cast as Int: 纬度不是字符串,而是Int,因此应转换为Int:

let data = userInfo?["lat"] as? Int ?? 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM