Swift Firebase设置时获取childByAutoId键 [英] Swift Firebase Get childByAutoId Key When Setting
本文介绍了Swift Firebase设置时获取childByAutoId键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在设置Firebase值时,我想获取.childByAutoId()
键值.是否可以这样做,或者我必须再次调用Firebase才能检索它?
I would like to obtain the .childByAutoId()
key value while I am setting a firebase value. Is this possible to do or do I have to recall firebase again to retrieve it?
ref.child("users").child(user.id).child("alerts").childByAutoId().setValue(["autoID" : .childByAutoIdValue])
例如:我需要它生成的AutoId,但想在设置Firebase值时获取它.
For Example: I need the AutoId that it generates but would like to obtain it while setting a firebase value.
let keyValue = ref.childByAutoId.key //Completley wrong but to better understand what im trying to do
*更新::这就是我实现了我试图做的事情.
*Update: This is how i achieved what I was trying to do.
let keyValue = ref.child("users").child(user.id).child("alerts").childByAutoId().key
ref.child("users").child(user.id).child("alerts").child(keyValue).setValue(["autoID" : keyValue])
用keyValue
代替childByAutoId()
推荐答案
尝试使用
var ref: DatabaseReference!
ref = Database.database().reference()
let keyValue = self.ref.child(name_of_child).childByAutoId().key
这篇关于Swift Firebase设置时获取childByAutoId键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文