0

I have this method which reads data from Firebase. However, when I want it to return a dictionary so I can use what I got from the Firebase, I get this problem:

"Unexpected non-void return value in void function"

which I don't understand because I do returning a dictionary (player) and I set the function to return a dictionary. this is the function:

func ReadTeamPlayers(teamName name: String) -> [String:Any]{
    ref.child(name).observeSingleEvent(of: .value) { (snapshot) in
        let player = snapshot.value as? [String:Any]
        return player
    }
}
John Doah
  • 1,839
  • 7
  • 25
  • 46
  • You are confusing your closure with your function. A closure is a essentially a function within another function. Your return is a return in the closure to the `observeSingleEvent()` function. You can't do that. You will need to rewrite your `readTeamPlayers()` function to take a closure, and all that closure once your call to `observeSingleEvent()` returns. – Duncan C Apr 08 '19 at 18:10
  • Thank you very much. I understand my mistake now. – John Doah Apr 08 '19 at 18:20

0 Answers0