Assuming "request" is defined and valid
func1()
// start using "X"
func func1() {
URLSession.shared.dataTask(with: request) { (data, response, error) in
// code, that eventually gets some values "a" and "b"
self.func2(a: a, b: b)
}.resume()
}
func func2(a: String, b: String) {
DispatchQueue.main.async {
// some UI stuff that needs to be done on the main thread
self.func3(a: a, b: b)
}
}
func func3(a: String, b: String) {
URLSession.shared.dataTask(with: request) { (data, response, error) in
// code, that eventually gets a value "X"
// HOW TO RETURN "X" ALL THE WAY BACK WHERE func1() IS CALLED?
}.resume()
}
I just typed this up manually, so there may be typos and other syntax errors (feel free to point them out)
So I have a few functions that I need to run one after another, which I can do, however, the last function generates a value "X", which is the value that I want. How can I return "X" from func3()
all the way back to where func1()
is called so that I can carry on and use it?