gpt4 book ai didi

ios - Firebase 真实数据库数据获取

转载 作者:行者123 更新时间:2023-11-28 14:03:06 26 4
gpt4 key购买 nike

我正在尝试获取以下值作为变量

enter image description here

但是我的代码给了我 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)
}

ً我错过了什么?

最佳答案

你只需要在这里做一个小改动:

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

Latitude 不是 String,而是 Int,因此转换为 Int:

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

关于ios - Firebase 真实数据库数据获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53340741/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com