【问题标题】:Ambiguous use of observe firebase DB模糊使用observe firebase DB
【发布时间】:2016-10-15 09:19:17
【问题描述】:

我真的不明白怎么回事?
我正在尝试从 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 = ..ref.child("Settings")
  • @Dravidian ref.child("设置")
  • 查看@ronatory 答案?并用实际错误更新您的问题
  • 有什么更新吗? @KeghamK。

标签: swift firebase firebase-realtime-database swift3


【解决方案1】:

改变这个:

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

【讨论】:

    【解决方案2】:

    你可以这样写你的电话:

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

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

    【讨论】:

      【解决方案3】:

      这个功能适合我:

      ref.child("Settings").child("service_types").observe(.childAdded, with: { (snapshot) -> Void in
          //your code
      }
      

      【讨论】:

        猜你喜欢
        • 2020-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多