Ambiguous use of observe firebase DB

2019-02-18 02:04发布

I really cannot get what is wrong?
I'm trying to load some settings data from firebase Settings node. Same code for other nodes in other functions work but this one is ambiguous. Why?

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.
    }

3条回答
beautiful°
2楼-- · 2019-02-18 02:21

this function for me:

ref.child("Settings").child("service_types").observe(.childAdded, with: { (snapshot) -> Void in
    //your code
}
查看更多
一纸荒年 Trace。
3楼-- · 2019-02-18 02:24

Change this:

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

}

to this:

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

})

See also firebase documentation section Listen for value events

查看更多
smile是对你的礼貌
4楼-- · 2019-02-18 02:35

You could write your call something like this:

ref
  .child("Settings")
  .child("service_types")
  .observe(.value) { (snapshot: FIRDataSnapshot) in
    // your code
  }

or

ref
  .child("Settings")
  .child("service_types")
  .observe(.value, with: { snapshot in
    // your code
  })
查看更多
登录 后发表回答