Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8582861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:24:03+00:00 2026-06-11T21:24:03+00:00

If there is a view controller that wants to execute a number of block

  • 0

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(self) where it is being called?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:24:05+00:00Added an answer on June 11, 2026 at 9:24 pm

    Your comment about ‘giving control’ back to the viewController (VC) doesn’t sense, in that the VC is usually sitting blocked in the runLoop callback, waiting for something to happen.

    If I understand what you want, its to have the opportunity to have other messages to the VC get processed while all this stuff is happening. Define a method:

    {
       NSMutableArray *blocks; // ivar
       BOOL isCanceled;
    }
    typedef void (^block_t)(id input);
    
    -(void)performBlock:(id)result;
    

    Create all the blocks at once or do it leisurely, but add them to the blocks array. Each block gets one object passed to it which contains the work items it needs.:

    block_t b = ^(id input) {
      ... do some work using input;
      NSDictionary *dict = ....; // a possible result of the work
      dispatch_async(dispatch_get_main_queue(), ^{ [self performBlock:dict; } );
    };
    

    The first block gets dispatched to some queue – could be a background queue too, and it sends its result back to the VC:

    -(void)performBlock:(id)result
    {
      if(isCanceled) { // some other method set this flag
      ...
      } else if([blocks count]) {
        block_t b = [blocks objectAtIndex:0];
        [blocks removeObjectAtIndex:0]; // guessing at method name
        dispatch_async(some queue, b);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several types os root view controller that I want to instantiate one
Example: I have a view controller and get rid of it. But there's still
Possible Duplicate: Passing only two variables between controller and view - best practice? There
Take the standard return statement for a controller: return View(Index); is there a way
Is there any other command for redirecting a controller to a particular view page
Is there best practice about display errors in during controller action executing on view?
I have a root view controller that opens up a new modal view controller.
In some MVC frameworks you can call controller action from the view if you
I have a UITabBarController that adds a viewController, but the positioning is off. There
In my project, there are two view controllers - let's say firstViewController and secondViewController.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.