【发布时间】:2019-04-26 15:08:02
【问题描述】:
我正在尝试将 firebase 快照保存到一个变量中,以便以后可以使用它重新写入 firebase,但是在获取数据后,我的应用程序崩溃了。我意识到我拥有的代码只是获取快照目录,而我的第二次尝试得到了我想要的数据,但无法将其分配给变量。
我尝试使用以下方法直接访问数据:
let name = Database.database().reference().child("Users").child(userId!).child("Name")
但这只会返回目录
下面是我想要做的:
@IBAction func checkInTapped(_ sender: Any) {
attendance.text = "Present"
guard !checkInClicked else {
UIAlertController.showAlert(message: "ERROR: You can only check in once for this Module!", vc: self)
return
}
let userId = Auth.auth().currentUser?.uid
let userEmail = Auth.auth().currentUser?.email
let moduleName = labelText
let name = Database.database().reference().child("Users").child(userId!).child("Name")
let currentDate = Date.getCurrentDate()
let currentTime = Date.getCurrentTime()
let presence = attendance.text
let ref = Database.database().reference().child("Attendance").child("Checkin").child(moduleName).child(currentDate).child(userId!)
let values = ["Email": userEmail!, "Check in Time": currentTime, "Attendance":presence] as [String : Any]
ref.setValue(values)
UIAlertController.showAlert(message: "You have checked in!", vc: self)
checkIn.isEnabled = false
checkOut.isEnabled = true
}
我正在尝试将按钮按下时的所有用户数据保存到 firebase,但也尝试从数据库中检索“名称”以将其保存到变量中并将其分配给“值”。我还是 swift 新手,所以任何帮助都将不胜感激
【问题讨论】:
标签: swift firebase firebase-realtime-database