在同一UID Firebase Swift下保存数据
我已经在Firebase实时数据库中添加了一些数据。它分为两个部分,用户和预订。我的问题是,当用户预订乘车时,它会提供不同的UID,我希望当用户书本骑行时,它处于同一UID之下。另外,如果开关打开,我想将其放在同一子节点下,预订,但是保存时它会变成不同的节点。任何帮助将不胜感激。
func Save(){
let key = ref.childByAutoId().key
let Booking = [
"id": key as Any,
"What Date": atALaterDate.text! as String,
"What Time": hoursMinutesTextField.text! as String,
"To What Time": ToWhatTime.text! as String,
"Requests or Notes": SRtextfield.text! as String
]
as [String : Any]
ref.child(key!).setValue(Booking)
}
在这里,我希望它与上面的节点结合使用。
func Save2(){
let key = ref.childByAutoId().key
if Switch.isOn{
let passengers = [
"Passengers": Stepperlabel.text! as String,
"passenger Age 1": AgeOfChild1.text! as String,
"passenger Age 2": AgeOfChild2.text! as String,
"passenger Age 3": AgeOfChild3.text! as String,
"passenger Age 4": AgeOfChild4.text! as String,
"passenger Age 5": AgeOfChild5.text! as String,
"passenger Age 6": AgeOfChild6.text! as String,
]
as [String : Any]
ref.child(key!).setValue("booking")
}else{
print("Hello")
return
}
}
I have added some data to the Firebase Realtime Database. It's in two parts, users and bookings. My problem is that when a user books a ride it gives a different uid, I would like it to be when a user books a ride it is under the same uid. Also, if the switch is on I would like to put it under the same child node, booking, but it comes into different nodes when saving. Any help would be highly appreciated.
func Save(){
let key = ref.childByAutoId().key
let Booking = [
"id": key as Any,
"What Date": atALaterDate.text! as String,
"What Time": hoursMinutesTextField.text! as String,
"To What Time": ToWhatTime.text! as String,
"Requests or Notes": SRtextfield.text! as String
]
as [String : Any]
ref.child(key!).setValue(Booking)
}
this is where I would like it to be under one node, in conjunction with the one above it.
func Save2(){
let key = ref.childByAutoId().key
if Switch.isOn{
let passengers = [
"Passengers": Stepperlabel.text! as String,
"passenger Age 1": AgeOfChild1.text! as String,
"passenger Age 2": AgeOfChild2.text! as String,
"passenger Age 3": AgeOfChild3.text! as String,
"passenger Age 4": AgeOfChild4.text! as String,
"passenger Age 5": AgeOfChild5.text! as String,
"passenger Age 6": AgeOfChild6.text! as String,
]
as [String : Any]
ref.child(key!).setValue("booking")
}else{
print("Hello")
return
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信问题是如何将其他数据添加到节点。
重要的一点是将要写入的节点保留并使用
update
来添加/更改现有数据的节点。如果更新
在不存在的节点上使用,则将添加。所以这是一个例子。假设我们有一个聊天应用程序,我们想编写一个 hello,world 的初始字符串,然后添加一个的额外字符串,该是什么
?以下结构
如果要一遍又一遍地重新使用节点,则可以将其引用作为var存储,然后在任何时候写入它,只需引用var ...
然后稍后在代码中的某个地方
,然后当您要添加其他数据时
I believe the question is how to add additional data to a node.
The important bit is to keep a reference to the node you want to write to and use it with
update
to add/change existing data. Ifupdate
is used on a node that doesn't exist, it will be added.So here's an example. Suppose we have a chatting app and we want to write an initial String of Hello, World, and then add an additional string of What's up? to that same node
this results in the following structure
If you want to re-use the node over and over, a reference to it could be stored as class var and then anytime you want to write to it, just reference the var...
then somewhere later in code
and then when you want to add additional data