gpt4 book ai didi

ios - AutoID 的 Swift Firebase 数据库数组

转载 作者:行者123 更新时间:2023-11-28 15:46:43 25 4
gpt4 key购买 nike

enter image description here enter image description here

  1. 我想将所有 ChilDBYAutoID 中的每个图形项接收到一个 double 组中。

  2. 另外,有没有更好的方法来使用计数而不是自动 ID?比如例子:

    0 7241 7442 7453 800...

我的主要目标是上传许多图形值,而不仅仅是更新一个。然后将图形值检索到 double 组中。

func uploadToFirebase(){

//Firebase Initialization
var ref: FIRDatabaseReference!
ref = FIRDatabase.database().reference()

ref.child("general_room_index").childByAutoId().setValue(["graph_value": totalCountY])

}

databaseRef.child("general_room_index").observeSingleEventOfType(.Value, withBlock: { (snapshot) in

snapshot.value!["medals"] as! [Double]

})

最佳答案

据我了解您的问题,您必须将 JSON 结构更改为:-

genera_Room_Index_Count : 3,

genera_Room_Index : {
1 : 123,
2 : 321,
3 : 565
}

将您的 genera_Room_Index_Count 初始化为 0;相同的安全规则将适用于 genera_Room_Index_Count 节点;然后开始附加值

 func uploadToFirebase(your_Value : Int){   // your_Value is your graph value as parameter

FIRDatabase.database().reference().child("genera_Room_Index_Count").observeSingleEvent(of: .value, with: {(Counts) in

let count = Counts.value as! Int + 1

print(count)

FIRDatabase.database().reference().child("genera_Room_Index").child(String(describing: count)).setValue(your_Value, withCompletionBlock: { (Err, Ref) in

print(Err ?? "No error")
print(Ref)

if Err == nil{

FIRDatabase.database().reference().child("genera_Room_Index_Count").runTransactionBlock({ (currentData) -> FIRTransactionResult in

var value = currentData.value as? Int

if value == nil {
value = 0
}

currentData.value = value! + 1

return FIRTransactionResult.success(withValue: currentData)

})
}
})
})
}

安全规则

"genera_Room_Index" :{

".read" : "true", // Or whatever your authentication flowchart might be
".write" : "true", // Or whatever your authentication flowchart might be


},

"genera_Room_Index_Count" :{

".read" : "true", // Or whatever your authentication flowchart might be
".write" : "true", // Or whatever your authentication flowchart might be


},

关于ios - AutoID 的 Swift Firebase 数据库数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42918543/

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