我收到此错误,但我正在尝试从字典中获取字符串.这是我的代码:
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数据库中,“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 } } })