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 8490005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:59:07+00:00 2026-06-10T21:59:07+00:00

I want to use blocks in my application, but I don’t really know anything

  • 0

I want to use blocks in my application, but I don’t really know anything about blocks. Can anyone explain how and why I should use blocks in my code?

  • 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-10T21:59:09+00:00Added an answer on June 10, 2026 at 9:59 pm

    Blocks are closures (or lambda functions, however you like to call them). Their purpose is that using blocks, the programmer doesn’t have to create named functions in the global scope or provide a target-action callback, instead he/she can create an unnamed, local “function” which can access the variables in its enclosing scope and easily perform actions.

    For example, when you want to e. g. dispatch an asynchronous operation, such an animation for views, without blocks, and you wanted to be notified of the competion, you had to write:

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:context:)];
    .... set up animation ....
    [UIView commitAnimations];
    

    This is a lot of code, furthermore it implies the presence of a valid self pointer – that might not always be available (I experience such a thing when I was developing MobileSubstrate-tweaks). So, instead of this, you can use blocks from iOS 4.0 and onwards:

    [UIView animateWithDuration:1.0 animations:^{
        // set up animation
    } completion:^{
        // this will be executed on completion
    }];
    

    Or, for example, loading online resources with NSURLConnection… B. b. (Before Blocks):

    urlConnection.delegate = self;
    
    - (void)connection:(NSURLConnection *)conn didReceiveResponse:(NSURLResponse *)rsp
    {
        // ...
    }
    
    - (void)connection:(NSURLConnection *)conn didReceiveData:(NSData *)data
    {
        // ...
    }
    
    // and so on, there are 4 or 5 delegate methods...
    

    A. B. (Anno Blocks):

    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *rsp, NSData *d, NSError *e) {
       // process request here
    }];
    

    Much easier, cleaner and shorter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want use JQuery mobile for the front-end of my mobile application, but I
I want to know, when my child process is exiting. But I don't want
I want use jQuery in my project. I know the javascript_include_tag calls the jQuery
I want to create my Android virtual device from another java application. I don't
We decided to use gwt modules in our application about 1 week ago. We
While my application runs a brief animation, I don't want the user to be
I don't want to use a library to make it more efficient. I've tested
I use Coffin to integrate Jinja2 with Django application. I want to use sorl
My question may not really be about realtime processing, but then again, it may

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.