我无法弄清楚如何通过 IBAction 将数据写入我的 Firebase 数据库。
我的问题是无法写入实际数据库,这是正在写入的数据类型。
我需要使用 Google map 服务地点对象写入数据。这是我的数据库写入代码:
let newWaitTime = Int(waitTimeLabel.text!)
let waitTime = databaseRef.child("times").child(place.placeID).childByAutoId()
waitTime.setValue(newWaitTime)
问题是因为 IBAction
函数不能接受其他参数,我不能将我的 place
变量传递到函数中,以便让我写到我的数据库。
我似乎无法找到解决方法,因为它需要知道 place.placeID
才能提交时间。没有它,就无法区分哪些时间属于哪些地点。有什么想法吗?
最佳答案
在主类中添加以下内容
var currentPlace: Place?
然后每当你与某个地方互动时
self.currentPlace = placeImInteractingWith
在 IBAction 中
if let placeToUse = currentPlace {
let waitTime = databaseRef.child("times").child(placeToUse.placeID).childByAutoId()
//etc
{
关于ios - 如何使用 IBAction 将数据写入 Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43623381/