如何在 firebase swift 4 中使用 childByAutoId 获取自动生成的数字

How to get hold of a auto generated number with childByAutoId in firebase swift 4

我使用 childByAutoId 在我的 firebase 数据库中创建了一个节点。现在我想用 swift 删除它。我如何获得对此自动生成的号码的引用?我正在考虑使用此代码:

func deleteAction(at indexPath : IndexPath) -> UIContextualAction {
    let action = UIContextualAction(style: .destructive, title: "Delete") { (action, view, completion) in
        let vinyl = self.vinyls[indexPath.row]
        guard let userID = Auth.auth().currentUser?.uid else { fatalError() }

        Database.database().reference().child("vinyls").child(userID).removeValue(completionBlock: { (error, _) in
            <#code#>
        })


    }
}

谢谢

你得到的值是

Database.database().reference().child("vinyls").observeSingleEvent(of: .value) { (snapshot) in

   let ref = snapshot.value as! [String:[String:Any]]

   // now you get ref where key is the auto-generated id and value is the dictionary you set with setValue before 

}