gpt4 book ai didi

ios - 为什么我不能以这种方式将数据添加到 Firebase 中?

转载 作者:行者123 更新时间:2023-11-29 00:27:41 29 4
gpt4 key购买 nike

我正在做一个与Firebase相关的项目,我尝试将数据上传到Firebase,如Firebase网站教程中的代码:

    // An index to track Ada's memberships
{
"users": {
"alovelace": {
"name": "Ada Lovelace",
// Index Ada's groups in her profile
"groups": {
// the value here doesn't matter, just that the key exists
"techpioneers": true,
"womentechmakers": true
}
},
...
},
"groups": {
"techpioneers": {
"name": "Historical Tech Pioneers",
"members": {
"alovelace": true,
"ghopper": true,
"eclarke": true
}
},
...
}
}

然后我按照这个结构写了我自己的数据结构,看起来是这样的:

func pushUser() {
let username = self.username
let userid = FIRAuth.auth()?.currentUser?.uid

let userInfo : [String : Any] = ["username" : username,
"userID" : userid,
"sggestedRoutes" : "",
"myTracedRoutes" : "",
"routes": {
"usualInfo" : true,
"calcuInfo" : true
}
]

let userRef = FIRDatabase.database().reference()
userRef.child("user").childByAutoId().setValue(userInfo)
}

在 Swift3 中,但调试器说嵌套路由{}不正确,我对此很困惑,有人可以给我提示吗?

亲切的问候


收到建议后,我对代码做了一些修改,但是Route部分还是不行:(

func pushUser() {
let username = self.username
let userid = FIRAuth.auth()?.currentUser?.uid

let userInfo : [String : Any] =
["username" : username,
"userID" : userid,
"sggestedRoutes" : "",
"uploadedRoutes" : "",
"myTracedRoutes" : "",
["Routes":
["usualInfo" : true,
"calcuInfo" : true]
]
]
let userRef = FIRDatabase.database().reference()
userRef.child("user").childByAutoId().setValue(userInfo)
}

最佳答案

尝试将路由添加为 ["routes": ["usualInfo": true, "calcuInfo": true]]

不要忘记 child “用户信息”和“路线”的正确闭包

关于ios - 为什么我不能以这种方式将数据添加到 Firebase 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42635811/

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