Swift – 无法将’__ NSCFString’类型的值转换为’NSDictionary
发布时间:2020-12-14 05:39:59 所属栏目:百科 来源:网络整理
导读:我收到此错误,但我正在尝试从字典中获取字符串.这是我的代码: FIRDatabase.database().reference().child("users").child(uid).observeEventType(.ChildAdded,withBlock: { (snapshot) in let dictionary = snapshot.value as! NSDictionary if let usernam
我收到此错误,但我正在尝试从字典中获取字符串.这是我的代码:
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 } } }) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |