ios - Swift Firebase Get childByAutoId Key When Setting
问题描述
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])
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])
used keyValue
in replacement of childByAutoId()
解决方案
尝试
var ref: DatabaseReference!
ref = Database.database().reference()
let keyValue = self.ref.child(name_of_child).childByAutoId().key
推荐阅读
- ios - ASNetworkImageNode gif 未加载
- php - 产品页面上的 Woocommerce 价格输出
- api - Docebo - 设置 OAuth JWT 不记名授权类型 - 公钥无效
- node.js - 循环请求时出错 [ERR_HTTP_HEADERS_SENT]
- javascript - 什么是 `fs.readFileSync` 但在浏览器中的等价物?
- bash - 带模式的循环环境,并输出自定义结果
- r - R 中的随机森林 - 19 个预测变量,1 个因变量
- python - cls vs. self vs. python中的类调用
- java - 复制静态方法的参数
- python - 代码中的错误是什么:“value %s 不是 int”% `value`