Avoiding Nested Blocks
- by Helium3
If there is a view controller that wants to execute a number of block based tasks one at a time, how can the control be given back to the view controller after a completion block has executed.
Lets say ViewControllerOne wants to execute a number of tasks, each relying on the result of the previous one, how would this control be given back to the viewcontroller after each completion block has been executed?
I started thinking about this and I was heading towards a deeply nested block pattern that will surely only cause confusion to whoever else reads or tests it.
A task executes and the completion block returns the result or error which is needed by the next task, which has its own completion task, that the next task relies on and so forth.
How can the control be managed in one place, the viewcontroller?
Would the completion block just call the next function that handles the next task, using a pointer to the view controller?