gpt4 book ai didi

swift - 在 Swift 中使用 Firebase,如何从集合中提取文档以在 TextView 中显示?

转载 作者:行者123 更新时间:2023-12-03 23:06:32 26 4
gpt4 key购买 nike

登录应用程序后,在设置页面中,SettingsViewController ,我希望用户能够在 TextView 中查看他们的信息。但是,无论读取数据的方法如何,我总是收到 Swift 编译器警告:

Cast from '[String]' to unrelated type 'String' always fails



这是我的代码:
func textViewFill() {

let db = Firestore.firestore()

db.collection("users").getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
for document in querySnapshot!.documents {
print("\(document.documentID) => \(document.data())")
let firstName = ["firstName"] as? String ?? ""
let lastName = ["lastName"] as? String ?? ""
let email = ["email"] as? String ?? ""
self.firstNameTextView.text = firstName
self.lastNameTextView.text = lastName
self.emailTextView.text = email
}
}
}
}

当我尝试将文档定义为字符串时出现警告:
let firstName = ["firstName"] as? String ?? ""
let lastName = ["lastName"] as? String ?? ""
let email = ["email"] as? String ?? ""

有没有办法将其显示为文本?

最佳答案

您正在尝试转换 ArrayString这里。这是您需要的:

let firstName = document.get("firstName") as? String ?? ""
let lastName = document.get("lastName") as? String ?? ""
let email = document.get("email") as? String ?? ""

关于swift - 在 Swift 中使用 Firebase,如何从集合中提取文档以在 TextView 中显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62351574/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com