[英]Firebase for iOS: childByAutoId() overrides the same child every time
I am working with Firebase for the second time now, but for the first with Firebase for iOS.(and with iOS in general) So I am using childByAutoId() which should be like push() for Android, right? 我现在第二次使用Firebase,但第一次使用iOS的Firebase。(以及与iOS一起使用)所以我正在使用childByAutoId(),它应该类似于Android的push(),对吗? My code is:
我的代码是:
let quoteString = ["base64": base64String]
let refPhotos = refPlace.childByAppendingPath("Images")
let refBase54 = refPhotos.childByAutoId()
refBase54.setValue(quoteString)
But every time photo is saved in Firebase the previously saved photo (it is only one for now) gets overridden by the new one. 但是,每次将照片保存在Firebase中时,以前保存的照片(目前仅一张)都将被新的照片覆盖。 The ID is changing and I can see that for a second Firebase is creating new child "Images" and the two photos are separately saved in two different Images children of Place.
ID正在更改,我可以看到第二个Firebase正在创建新的子级“图像”,并且这两张照片分别保存在Place的两个不同“图像”子级中。 And then it is gone.
然后它消失了。
So am I missing something obvious or is this a bug or any other advise is very welcome. 因此,我是否遗漏了一些明显的东西,或者这是一个错误或任何其他建议,我们非常欢迎。
Update: 更新:
my json data 我的json数据
"Places" : {
"ChIJMaArcCHP5zsRKU_FpbNldp8" : {
"Comments" : {
"-K9xX2KBCiOZMthtbxSy" : "Foo"
},
"ID" : "ChIJMaArcCHP5zsRKU_FpbNldp8",
"Images" : {
"-K9xX2KUPSLGvFZpI-XL" : {
"base64" : "very long"
}
... and so on. ... 等等。 After exploring it a little - what can be seen in the moment of writing is both "Images" and "Comments" appear twice in red and green color(new is created, old is deleted).
经过一番探索后,在撰写本文时可以看到“图像”和“评论”都以红色和绿色两次出现(创建了新的,删除了旧的)。 This is not the goal of childByAppendingPath(), right?
这不是childByAppendingPath()的目标,对吗?
I just ran this snippet a few times: 我只运行了几段:
var rootRef = Firebase(url: "https://stackoverflow.firebaseio.com/35258493")
override func viewDidLoad() {
super.viewDidLoad()
let quoteString = ["base64": "SAIUH IE WE E EUWG EWG YGEFWU GEWOGEW "]
let refPhotos = rootRef.childByAppendingPath("Images")
let refBase54 = refPhotos.childByAutoId()
refBase54.setValue(quoteString)
}
And ended up with this data: 并最终得到以下数据:
{
"Images": {
"-K9y4C3NhndlH9LwR7B4": {
"base64": "SAIUH IE WE E EUWG EWG YGEFWU GEWOGEW "
},
"-K9y4I3otW6hV59C6Z2G": {
"base64": "SAIUH IE WE E EUWG EWG YGEFWU GEWOGEW "
}
}
}
So the second "image" was clearly not replacing the first one. 因此,第二个“图像”显然不能替代第一个。
Not sure if you worked this out. 不知道您是否解决了这个问题。 But I was also facing the same issue.
但是我也面临着同样的问题。 My code was inside a
UIButton
action and all my new entries kept getting deleted and only the latest one was retained. 我的代码在
UIButton
动作中,所有新条目均被删除,仅保留了最新条目。 Setting the refs to nil at the end of the action solved my issue and I started seeing the multiple entries in the dashboard. 在操作结束时将refs设置为nil可以解决我的问题,并且我开始在仪表板中看到多个条目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.