【问题标题】:How to by pass Firebase Swift 3 Ambiguous reference to member 'observe(_:with)' error?如何绕过 Firebase Swift 3 Ambiguous reference to member 'observe(_:with)' 错误?
【发布时间】:2017-05-06 11:23:10
【问题描述】:

我知道过去曾有人问过这个问题,但是我找不到适用于 swift 3 的解决方案。有人能指出我正确的方向吗?这是我的代码:

    ref.child(uid).child("flights").observe(.value, with:{  (snapshot: FIRDataSnapshot!) -> Void in
        self.messages.append(snapshot)

        let row = [IndexPath(row: self.messages.count-1, section: 0) ]


        print(snapshot)

        self.flightTableView.insertRows(at: row, with: .automatic)

        DispatchQueue.main.async {
            self.flightTableView.reloadData()
        }
    })

}

【问题讨论】:

    标签: firebase firebase-realtime-database swift3


    【解决方案1】:

    我将代码分成两个语句,它开始工作。

        let child:FIRDatabaseReference = ref.child(uid).child("flights")
    
    
        child.observe(.childAdded) { (snapshot:FIRDataSnapshot) in
            print(snapshot)
        }
    

    【讨论】:

      【解决方案2】:

      Swift 3 和 Firebase 3.17.0

      这样就可以了,试试这段代码

              let ref = FIRDatabase.database().reference().child("uid").child("flights")
              ref.observe(.value, with: { (snapshot) in
                  print("Success get the snapshot \(snapshot)")
                  // do something with snapshot than
                  DispatchQueue.main.async {
                      self.yourTableView.reloadData()
                  }
              }) { (error) in
                  print("Failed get the snapshot \(error.localizedDescription)")
                  // do something to handle error
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-08-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-26
        • 1970-01-01
        • 2018-04-06
        • 1970-01-01
        相关资源
        最近更新 更多