我得到这个错误,但我试图让一个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
}
})
在我的Firebase数据库中, “名称”和“登录”都是字符串。我不明白是什么问题。
任何帮助将不胜感激!
问题涉及快照投向NSDictionary。由于快照值是一个字符串。试试这个:
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
}
}
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句