gpt4 book ai didi

swift - Firebase (3.2.0) 使用 Swift (2.0) 查询的确切方式是什么?

转载 作者:行者123 更新时间:2023-11-30 10:03:04 24 4
gpt4 key购买 nike

我一直在尝试使用他们的指南查询我的 firebase 数据库,但无法正确返回结果。如果有人能指出我做错了什么或纠正我,那将非常有帮助。

这是我的代码片段

let ref = DataService.dataService.BASE_REF
let myQuery = (ref.child("testing")).queryOrderedByKey()
let MyQuery1 = (ref.child("testing")).queryOrderedByValue()
let MyQuery2 = (ref.child("testing")).queryEqualToValue("Alphaa")
let MyQuery3 = (ref.child("testing")).queryEqualToValue("Alphaa", childKey: "Alpha")
myQuery.observeSingleEventOfType(.Value, withBlock: {
snapshot in
print("Ordered By Key")
print(snapshot.value)
})

MyQuery1.observeSingleEventOfType(.Value, withBlock: {
snapshot in
print("Ordered by Value")
print(snapshot.value)
})

MyQuery2.observeSingleEventOfType(.Value, withBlock: {
snapshot in
print("Value Equal")
print(snapshot.value)
})

MyQuery3.observeSingleEventOfType(.Value, withBlock: {
snapshot in
print("Ordered by Value & Key")
print(snapshot.value)
})

这是结果屏幕按键排序和按值排序都无法解决问题。

Optional({
Alpha = Gammaa;
Alright = 24;
Beta = Betaa;
Delta = Deltaa;
Epsilon = Epsilonn;
Eta = Etaa;
Gamma = Alphaa;
Iota = Iotaa;
Lets = 3;
Okay = 1;
Theta = Thetaa;
Zeta = Zetaa;
beep = 4;
boop = 11;
})

两个值都相等并且按值和键排序给我可选(null)

JSON 表值

"testing" : {
"Alpha" : "Gammaa",
"Alright" : 24,
"Beta" : "Betaa",
"Delta" : "Deltaa",
"Epsilon" : "Epsilonn",
"Eta" : "Etaa",
"Gamma" : "Alphaa",
"Iota" : "Iotaa",
"Lets" : 3,
"Okay" : 1,
"Theta" : "Thetaa",
"Zeta" : "Zetaa",
"beep" : 4,
"boop" : 11
}

我试图返回相等的值或从服务器端而不是在客户端对其进行排序。

最佳答案

我继续测试并改变了获得结果的方式

 MyQuery1.observeSingleEventOfType(.Value, withBlock: {
snapshot in
print("************")
print("Ordered by Value")
for snap in snapshot.children {
print(snap);
}
})

这给了我想要的值结果:D以及键

Ordered by Value
Snap (Okay) 1
Snap (Lets) 3
Snap (beep) 4
Snap (boop) 11
Snap (Alright) 24
Snap (Gamma) Alphaa
Snap (Beta) Betaa
Snap (Delta) Deltaa
Snap (Epsilon) Epsilonn
Snap (Eta) Etaa
Snap (Alpha) Gammaa
Snap (Iota) Iotaa
Snap (Theta) Thetaa
Snap (Zeta) Zetaa

关于swift - Firebase (3.2.0) 使用 Swift (2.0) 查询的确切方式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37410561/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com