Ios 快速火基函数返回

Ios 快速火基函数返回,ios,swift,firebase,swift3,firebase-realtime-database,Ios,Swift,Firebase,Swift3,Firebase Realtime Database,我很难在返回函数中使用Firebase值。这对我来说似乎是一个持续的问题。我已经为我的问题写了一个基本的例子。我该怎么做呢 func getChartIndexValues(completion:@escaping (Double) -> ()) { //Firebase Initialization var ref: FIRDatabaseReference! ref = FIRDatabase.database().reference() ref.c

我很难在返回函数中使用Firebase值。这对我来说似乎是一个持续的问题。我已经为我的问题写了一个基本的例子。我该怎么做呢

func getChartIndexValues(completion:@escaping (Double) -> ()) {

    //Firebase Initialization
    var ref: FIRDatabaseReference!
    ref = FIRDatabase.database().reference()

    ref.child("general_room_index").observeSingleEvent(of: .value, with: {(snapshot) in

        let snapDict = snapshot.value as? NSDictionary
        var zero = snapDict?["0"] as! Double

        completion(zero)
        })

}


   returnFunction() -> (Double) {

      getChartIndexValues() { (zero) -> () in

            let testValue = zero
        }


     return //THis is my problem
}

你已经暗示了你的问题,但没有明确说明。问题是不能将异步函数的结果作为函数结果返回。您需要传入一个在函数完成时运行的完成处理程序,并且该代码就是可以访问结果的代码

returnFunction() -> (Double) {

  getChartIndexValues() { (zero) -> () in

    //Your code to process the results belongs here
    self.someInstanceVar = zero
    someLabel.text = "Your result is \(zero)"
    }

}
//You CAN'T put your code to process results here.

那么你的意思是我不能绕过块来返回函数中的值?我必须把它分配给一个标签或任何我想分配给它的东西?