- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从 Firebase Firestore 获取数据。我成功地获取了数据,但是,我将其显示在 UITableView 中,并且我需要它来实时获取数据。我正在使用 getDocuments
方法,但无法添加快照监听器,因为我无法覆盖 getDocuments
参数。
func loadPartiesDataFromFirebase() {
let db = Firestore.firestore()
db.collection("parties").getDocuments() { snapshot, err in
if let err = err {
print("Error getting documents: \(err)")
} else {
for document in (snapshot!.documents) {
let title = document.data()["title"] as? String ?? "New Party"
let location = document.data()["location"] as? String ?? "No Location"
let date = document.data()["date"] as? String ?? "No Date"
let startTime = document.data()["startTime"] as? String ?? "No Start Time"
let endTime = document.data()["endTime"] as? String ?? "No End Time"
self.parties.append(Party(title: title, location: location, date: date, startTime: startTime, endTime: endTime))
}
}
self.yourPartiesTableView.reloadData()
}
我希望它能够持续实时显示来自 Firestore 的数据。我怎样才能在 Swift 中做到这一点?
最佳答案
您需要向集合添加一个监听器。
let db = Firestore.firestore()
let listener = db.collection("parties").addSnapshotListener { (snapshot, error) in
switch (snapshot, error) {
case (.none, .none):
print("no data")
case (.none, .some(let error)):
print("some error \(error.localizedDescription)")
case (.some(let snapshot), _):
print("collection updated, now it contains \(snapshot.documents.count) documents")
}
}
此外,您可以存储对监听器的引用,并在不需要时将其删除。
listener.remove()
关于swift - 在 Swift 中写入 Firestore 时,如何将 addSnapshotListener 方法与 getDocument 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56177500/
我的代码从 Firestore 检索数据时遇到问题。 我的代码中有 2 个类:Exercise 和 Tag。我的 FirestoreDatabase 中有 2 个集合:练习和标签 我需要从“练习”集合
我只是想测试一些有关获取 UniversalID 的内容: 我创建一个计算字段: 当我撰写文档时。 Xpage 上的内容,计算字段已经有一些 UNID,并且如果我点击刷新,它就会发生变化。 Lo
我正在从关系数据库迁移到 NOSQL,并且我已经阅读了整个 Firebase 文档,现在我正着手进行一个研究项目以了解更多相关信息。 我想做的是:我有一个 user_profile,Auth 创建的每
我正在尝试使用位于网络驱动器上的 Java 来解析 XML 文件...我已在此处查看了大量 XML 解析信息,但找不到我需要的答案...问题是 getDocument() 例程不断返回空值,即使解析器
错误:调用 DocuSign\eSign\ObjectSerializer::deserialize() 中字符串的成员函数 read()(/vendor/docusign/esign-client/
我试图通过执行一系列计算购物车中商品总和的 for 循环调用来获取 Firestore 中购物车的总数。 购物车存储在一个名为 carts 的表中,出现时的 View 被拉入一个名为 cartCach
我是 MFC 的新手,我想在对话框中获取一些数据,但这不起作用, CTestDoc* pDoc=GetDocument(); pDoc->Get(...); 我谷歌了一下,发现 GetDocument
我在尝试从 initState 中的 Firestore 调用文档时遇到问题。我可以从 StreamBuilder 中提取数据就好了,但我只想在 initState 上调用一次数据。 这是我在做什么:
我正面临 Firebase 快照的问题。我成功地将我的 Fierbase 帐户与我的 Xcode 项目联系起来。我能够更改 Firestore 云中的数据。但我无法阅读。这是我的功能: class U
我是 javascript/nodeJS 的新手。我正在尝试实现一个 http firebase 云函数,它在它的主体中接收 userID。收到后,我需要调用 firestore getDocumen
我正在使用 getDocuments() 获取集合中的所有文档。 Firestore 是每次都“下载”所有文档,还是只下载更改的文档,而未更改的文档从 Firestore 的本地缓存中检索? 最佳答案
我想在 dlg 类中得到一个 doc*,我知道在 View 类中我们可以得到 doc* doc* pdc=getdocument(); 但是我怎样才能在 dlg 类中做到这一点呢? 最佳答案 CDia
好吧,我想覆盖 JTextArea 的 Document 的 remove 方法,我不知道要扩展什么类。我无法扩展 Document,因为它是一个接口(interface),这也意味着它不能是 JTe
当我尝试获取一个不存在的 Firestore 文档时,我的应用崩溃了 Firestore 文档说我应该得到一个空文档,而不是终端错误 https://firebase.google.com/docs/
本文整理了Java中org.xhtmlrenderer.resource.XMLResource.getDocument()方法的一些代码示例,展示了XMLResource.getDocument()
本文整理了Java中com.yahoo.text.XML.getDocument()方法的一些代码示例,展示了XML.getDocument()的具体用法。这些代码示例主要来源于Github/Stac
FirebaseFirestore.instance.collection('locations').getDocuments().then((docs){ if(docs.documen
我想读取一个文档,从该文档中获取一个字段,并将一个变量设置为该字段的值 我希望在 Firebase getDocument 函数之外声明的变量被写入。实际结果是变量被写入 Firebase getDo
我有一个 XPage,由于(本来应该是)一个小更改而刚刚损坏。 如果我运行(其中 document1 是 NotesXSPDocument 数据源): document1.replaceItem("I
在尝试从内容类型为“text/html”的 JTextPane 组件获取文本(在其位置上带有换行符)时,我做错了什么 ? textPane.getText() 返回 HTML,但内容为空 head 和
我是一名优秀的程序员,十分优秀!