Avoiding Nested Blocks

Posted by Helium3 on Stack Overflow See other posts from Stack Overflow or by Helium3
Published on 2012-09-12T15:36:44Z Indexed on 2012/09/12 15:37 UTC
Read the original article Hit count: 219

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?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about ios