I have a function like this
func fetchPokemons() -> [Pokemon] {
var pokemons : [Pokemon] = []
service.fetchPokemons().done{ (newPokemons) in
pokemons += newPokemons.pokemons!
print(pokemons)
}.catch { (error) in
print(error)
}
print(pokemons)
return pokemons
}
I need to get pokemons and then put them into array. My problem is obvious. Promises are asynchronous that's why my function returns empty array. .then function used to return another Promise and .done returns Void. So how should I write a completion handler to return filled array of Objects?