我需要从孩子那里加载文字"尼克" 我的程序每次都在void上更改标签文本:(
这是我的代码:
ref = Database.database().reference()
refHandle = ref.observe(DataEventType.value, with: { (snapshot) in
let dataDict = snapshot.value as! [String: AnyObject]
print(dataDict)
})
let userID: String = (Auth.auth().currentUser?.uid)!
ref.child("Users").child(userID).child("Nick").observeSingleEvent(of: .value, with: {
snapshot in
print(snapshot)
let m = snapshot.value as? String
self.label.text = m
})
答案 0 :(得分:0)
您必须从快照值中取值“Nick”。所以你的代码看起来像这样:
let userID: String = (Auth.auth().currentUser?.uid)!
ref.child("Users").child(userID).child("Nick").observeSingleEvent(of: .value, with: {
snapshot in
guard let value = snapshot.value as? [String: Any] else { return }
guard let name = value["Nick"] as? String else { return }
let m = name
self.label.text = m
})