【发布时间】:2019-05-22 05:47:25
【问题描述】:
我正在尝试从 firebase 显示我的用户名,但是这行代码:
self.userNameOut.text! = DataSnapshot.value!["username"] as? String
返回错误:
Cannot subscript a value of incorrect or ambiguous type
有人知道我为什么会收到这个错误吗?
任何帮助将不胜感激!
编辑: 我认为我与数据库的连接是错误的..
var loggedInUser = AnyObject?.none
var databaseRef = DatabaseReference()
var storageRef = StorageReference()````
self.loggedInUser = Auth.auth().currentUser
self.databaseRef.child("user_profiles").child(self.loggedInUser!.uid).observeSingleEvent(of: .value) { (snapshot:DataSnapshot) in
if snapshot.exists() {
if let userDict = snapshot.valueInExportFormat() as? Dictionary<String, AnyObject> {
print(userDict["username"] as! String )
self.userNameOut.text = userDict["username"] as? String ?? ""
}
}
【问题讨论】:
标签: ios swift firebase firebase-realtime-database