我正在尝试从 Firebase 数据库获取特定值。我查阅了一些文档,比如Google的,但我无法做到。这是数据库的 JSON 文件:
{
"Kullanıcı" : {
"ahmetozrahat25" : {
"E-Mail" : "[email protected] /cdn-cgi/l/email-protection",
"Yetki" : "user"
},
"banuozrht" : {
"E-Mail" : "banuozr[email protected] /cdn-cgi/l/email-protection",
"Yetki" : "user"
}
}
}
SWIFT代码:
ref?.child("Kullanıcı").child(userName.text!).observeSingleEvent(of: .value, with: { (snapshot) in
if let item = snapshot.value as? String{
self.changedName = item
}
})
我想要得到E-Mail
用户的价值,而不是所有人的价值。我怎样才能做到这一点?
最后我找到了解决方案。如果我声明一个 var 并尝试稍后使用它会返回 nil,但是如果我尝试使用snapshot.value as? String
没关系。这是我做的一个例子。
ref: FIRDatabaseReference?
handle: FIRDatabaseHandle?
let user = FIRAuth.auth()?.currentUser
ref = FIRDatabase.database().reference()
handle = ref?.child("Kullanıcı").child((user?.uid)!).child("Yetki").observe(.value, with: { (snapshot) in
if let value = snapshot.value as? String{
if snapshot.value as? String == "admin"{
self.items.append("Soru Gönder")
self.self.tblView.reloadData()
}
}
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)