我正在尝试获取以下值作为变量
但是我的代码给了我零
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 不是字符串,而是 Int,因此转换为 Int:
let data = userInfo?["lat"] as? Int ?? 0
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句