I'm generating a ticker which retrieves data from the api using dataTask
and returns to the function via succsss
The function which gets the response needs to append or concatenate them in sequence, however I'm unable to get that done.
Here is what I've tried, both fail as the last print line executes before the individual ticker success call returns.
func getTicker() {
var tickerText = ""
tickerText += dataRequestnew("https://api-path-here/1") { success in return "First-item: \(success)" }
tickerText += dataRequestnew("https://api-path-here/2") { success in return " | Second-item: \(success)" }
print(tickerText)
}
Or
var tickerText = ""
func getTicker() {
dataRequestnew("https://api-path-here/1") { success in
self.tickerText += "First-item: \(success)"
print(self.tickerText)
}
dataRequestnew("https://api-path-here/2") { success in
self.tickerText += " | Second-item: \(success)"
print(self.tickerText)
}
print(self.tickerText)
}
In the second example, the individual ticker prints successfully, but not the last one, it returns the default value only.
Question
How can I make the code run in sequence or at least make sure that the last print works once all the tickerText calls are returned successfully.
Thanks.