更新并从Firestore中删除数据

时间:2017-12-15 06:51:17

标签: ios swift firebase google-cloud-firestore

我尝试在控制台Firestore中修改或删除数据,并希望在我的应用中看到更改。我使用这段代码:

func checkForUpdates() {
    db.collection("sweets").addSnapshotListener { querySnapshot, error in
        //        whereField("name", isEqualTo: String.self).addSnapshotListener { order(by: "name")
        //whereField("timeStamp", isGreaterThan: Date()).addSnapshotListener {

        guard let snapshot = querySnapshot else {return}

        snapshot.documentChanges.forEach {
            diff in

            if (diff.type == .added) {
                self.sweetArray.append(Sweet(dictionary: diff.document.data())!)
                DispatchQueue.main.async {
                    self.tableView.reloadData()
                }
            }

            if (diff.type == .modified) {
                print("document modified")
                DispatchQueue.main.async {
                    self.tableView.reloadData()
                }
            }

            if (diff.type == .removed) {
                print("document removed")
                self.tableView.reloadData()
            }
        }
    }
}

我需要在if (diff.type == .modified)if (diff.type == .removed)撰写哪些内容?

如果我在控制台Firestore中修改或删除数据,我会在控制台xCode print("document modified")print("document removed")中看到。

0 个答案:

没有答案