Ego*_*sov 7 firebase swift firebase-realtime-database
我收到了这个错误,但我正试图从中得到String
一个Dictionary
.这是我的代码:
FIRDatabase.database().reference().child("users").child(uid).observeEventType(.ChildAdded, withBlock: { (snapshot) in
let dictionary = snapshot.value as! NSDictionary
if let username = dictionary["name"] as? String {
cell.name.text = username
}
if let userlogin = dictionary["login"] as? String {
cell.login.text = userlogin
}
})
Run Code Online (Sandbox Code Playgroud)
在我的Firebase数据库中, "name"和"login"都是字符串.我无法理解这是什么问题.
任何帮助将不胜感激!
问题将快照转换为NSDictionary.由于快照值是String.试试这个:
FIRDatabase.database().reference().child("users").child(uid).observeEventType(.ChildAdded, withBlock: { (snapshot) in
if let dictionary = snapshot.value as? NSDictionary {
if let username = dictionary["name"] as? String {
cell.name.text = username
}
if let userlogin = dictionary["login"] as? String {
cell.login.text = userlogin
}
}
})
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7544 次 |
最近记录: |