【发布时间】:2021-09-08 15:22:27
【问题描述】:
我正在尝试将一些用户数据添加到我的 firebase 实时数据库中,但是当我尝试使用数据添加子节点时,我在下面收到此错误。我尝试将userData 变量的类型更改为String,但没有任何改变。
错误:
Cannot convert value of type '[String : String?]' to expected argument type 'String'
我的代码:
private func firebaseAuthentication(withUser user: GIDGoogleUser) {
if let authentication = user.authentication {
let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
Auth.auth().signIn(with: credential) { (_, error) in
if let error = error {
print(error.localizedDescription)
} else {
// Add user data to real-time db if user does not already exists
let userData = [
"id" : Auth.auth().currentUser?.uid,
"email" : Auth.auth().currentUser?.email,
"name" : Auth.auth().currentUser?.displayName,
"photoUrl": "none",
"premium": "false"
]
ref.observeSingleEvent(of: .value) { snapshot in
if !snapshot.hasChild(Auth.auth().currentUser?.uid ?? "noid") {
// user does not exist
usersRef.child(Auth.auth().currentUser?.uid ?? "noid").child(userData) // here i'm getting the error
}
} withCancel: { error in
}
self.state = .signedIn
}
}
}
}
【问题讨论】: