swift - 模棱两可地使用 observe firebase DB

标签 swift firebase firebase-realtime-database swift3

我真的不知道哪里出了问题?
我正在尝试从 firebase Settings 节点加载一些设置数据。其他功能中其他节点的相同代码有效,但这个代码不明确。为什么?

var ref:FIRDatabaseReference!  //Global variable

     override func viewDidLoad() {
        super.viewDidLoad()


        self.mapView.delegate = self

            if CLLocationManager.locationServicesEnabled() {

                locationManager.delegate = self
                locationManager.desiredAccuracy = kCLLocationAccuracyBest
                locationManager.requestWhenInUseAuthorization()
                locationManager.startUpdatingLocation()

              //  monitorRegion()

            } else {

                // Alert to enable location services on iphone first
            }

            ref = FIRDatabase.database().reference(fromURL: "https://*******.firebaseio.com/")
            //The error is here
            ref.child("Settings").child("service_types").observe(.value) { (snapshot) in

            }


        // Do any additional setup after loading the view.
    }

最佳答案

改变这个:

ref.child("Settings").child("service_types").observe(.value) { (snapshot) in

}

为此:

ref.child("Settings").child("service_types").observe(.value, with: { snapshot in

})

另见 firebase documentation section Listen for value events

关于swift - 模棱两可地使用 observe firebase DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40057276/

相关文章:

javascript - 我是 firebase 的新手,但已经使用 java 脚本有一段时间了,但我不明白 snap => 的作用以及为什么使用它

firebase - 我们如何将 Firebase 托管与 Firebase 实时数据库/存储集成?

json - 从 JSON 解码为自定义对象

ios - 使用 UpdateChildValue 从 Firebase 编辑

firebase - Exists() 不适用于第二个变量 Cloud Firestore 规则

swift - 使用 firebase 和 swift 将帖子分页到 Collection View

swift - 使用默认属性值初始化对象

swift - 循环遍历场景中的所有对象/ Sprite

ios - 读取当前用户的数据?

javascript - Angular2/Firebase - Array1 等于 array2 而不将它们绑定(bind)在一起