首页 > 解决方案 > 如何快速检索唯一 ID 以将其删除(Firebase)

问题描述

我如何能够快速访问 Firebase 的唯一 ID?我已经尝试了这个论坛的几乎所有内容,我正在尝试快速删除表格单元格中的某个节点:

在此处输入图像描述

我尝试从用户电子邮件创建引用,并在字典中检索 ID,但是当我尝试从“indexPath”引用它时,它返回 ID。

我尝试了一个 int、string、any 类型的 Array;那些对我大喊大叫的人。

我已经包含了一些示例代码:

 func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {

        var currentEmail = Auth.auth().currentUser?.email as String?

        if(editingStyle == .delete) {
            let ref = Database.database().reference()

            ref.child(currentEmail!).observe(.value, with: { snapshot in

                if !snapshot.exists() {return} //may want to add better error handling here.

                let info = snapshot.value as! NSDictionary

                let reff = info.index(ofAccessibilityElement: indexPath)

                print("info keys are:", reff)
            })
        }

标签: swiftfirebasefirebase-realtime-database

解决方案


你试过snapshot.key吗?例子:

self.uid = 快照.key


推荐阅读