You can´t just return words
in your closure
. First of all it´s an async method second you need to return a value outside of the closure which will be called before the closure. You need to have a completionHandler
instead of returning Array<Any>
. In that case you can pass the value if and when it succeeds. Something like this:
func getWords(onCompletion: @escaping (Array<Any>) -> Void) {
ref = Database.database().reference()
ref.child("addedWords").observe(.value, with: { (DataSnapshot) in
var tempWords = DataSnapshot.value as! [String:AnyObject]
var words = Array(tempWords.keys)
print(words)
onCompletion(words)
})
}
To call it:
getWords(onCompletion: { (words) in
print(words)
})
solved Unexpected non-void return value in void function when returns an array