【发布时间】:2019-04-05 16:08:33
【问题描述】:
我正在尝试从 Firebase Firestore 读取数据,但无法将文档数据存储在变量中,因为这些变量只是本地变量,并且会被“垃圾收集”
我尝试创建一个尝试返回文档内容的函数,但由于“getDocument”方法不允许返回类型,因此导致错误。
docRef.getDocument { (document, error) in
if let document = document, document.exists {
let dataDescription = document.data().map(String.init(describing:)) ?? "nil"
var dataValues = document.data()!.values
self.textInput = dataDescription
//I first tried doing it without the word self, but it gave an error insisting that I add self, but adding it makes it a local variable and not the String variable defined in the class
//textInput is a String
print("Document data: \(document.data()!.values)")
//This will print out everything in the document
} else {
print("Document does not exist")
}
}
我正在尝试查看是否可以为文档数据设置任何变量,并且在读取数据库后仍然能够访问数据。
【问题讨论】:
标签: ios swift firebase google-cloud-firestore