【发布时间】:2019-11-26 09:26:32
【问题描述】:
当我尝试在 Swift 中打印/分配键/值数据时,数据会被括号括起来。我想隐藏/剪切括号。
已使用以下代码在 Swift 中进行了测试。
func listenForChanges() {
let db = Firestore.firestore()
db.collection("Block").document("Test")
.addSnapshotListener { documentSnapshot, error in
guard let document = documentSnapshot else {
print("Error fetching document: \(error!)")
return
}
guard let data = document.data()?.values else {
print("Document data was empty.")
return
}
self.syncText.text = "\(data)"
}
}
当前结果是 -> [值]
预期结果应该是 -> 值
有什么隐藏括号的建议吗?
【问题讨论】:
-
阅读文档/尝试了解
data的类型和从那里开始! firebase.google.com/docs/reference/swift/firebasefirestore/api/… -
我会假设
document.data()?.values返回一个数组,这也可以解释[value]。如果您的数据返回数组中的单个值,请尝试print(data.first) -
document.data()?是一个字典,.values 只是没有键的值
标签: ios swift dictionary google-cloud-firestore