swift - 为什么我的 swift firestore getDocument 查询没有返回任何内容?
问题描述
swift 和一般编码的新手,专门使用 swiftUI。
在查看了 swift SDK 的文档后,我尝试实现一个基本查询来检查集合中是否存在文档。我已经阅读了类似问题的答案,但据我所知与我的问题没有直接关系。
这是我指的文档: https ://firebase.google.com/docs/firestore/query-data/get-data
这是代码:
let fullrefplacesIndex = db.collection("users").document(currentUserId!.uid).collection("places").document("placesIndex")
fullrefplacesIndex.getDocument { (document, error) in
print("This line does not get executed")
if let document = document, document.exists {
let dataDescription = document.data().map(String.init(describing:)) ?? "nil"
print("places index Document data: \(dataDescription)")
} else {
print("places index Document does not exist")
}
}
print("This is the first line executed after the getDocument method call.")
它是从文档中逐字提取的,但是当我运行它时,它会执行第一行来调用 getDocument 方法,然后就没有别的了。直到方法调用的尾随关闭之后,才执行 'if let' 可选绑定行或其下方的任何内容。
其他信息:
- 代码是方法的一部分,该方法是作为环境对象实例化的类的一部分。
- 呼叫来自视图中的按钮。
- 路径参考正确且有效。
是因为它是异步运行的吗?我需要添加一个监听器?如果是这样,有人可以指导我如何执行此操作,以便它在收到来自服务器的回调时检查文档是否存在?
谢谢!
解决方案
推荐阅读
- wordpress - Wordpress - 如何在社交分享中添加自定义文本和链接?
- javascript - 在一个循环中抓取接下来的 N 个项目
- python - Pytorch 中两个类的一个热编码
- python - 叶问题jupyter笔记本:它没有在地图上显示颜色
- java - 如何让我的 JButton 计数并更改我的显示?
- mdx - 使用 mdx 计算计算最近 12 周的平均值
- node.js - 用于清理请求错误日志的 NPM 包
- python - pd.groupby:如何对同一组中的列进行分组
- c# - 如何在 web api 响应 (html) 中选择特定的 DIV
- javascript - 我正在尝试更改博览会相机上的闪光模式,但似乎没有任何效果(反应原生:功能组件)