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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:56:15+00:00 2026-05-29T08:56:15+00:00

Block syntax in Objective C (and indeed C, I presume) is notoriously incongruous. Passing

  • 0

Block syntax in Objective C (and indeed C, I presume) is notoriously incongruous. Passing blocks as arguments looks different than declaring blocks as ivars, which looks different than typedefing blocks.

Is there a comprehensive list of block-declaration syntax that I could keep on hand for quick reference?

  • 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-05-29T08:56:16+00:00Added an answer on May 29, 2026 at 8:56 am

    List of Block Declaration Syntaxes

    Throughout, let

    • return_type be the type of object/primitive/etc. you’d like to return (commonly void)
    • blockName be the variable name of the block you’re creating
    • var_type be the type object/primitive/etc. you’d like to pass as an argument (leave blank for no parameters)
    • varName be the variable name of the given parameter

    And remember that you can create as many parameters as you’d like.

    Blocks as Variables

    Possibly the most common for of declaration.

    return_type (^blockName)(var_type) = ^return_type (var_type varName)
    {
        // ...
    };
    

    Blocks as Properties

    Much like declaring blocks as variables, however subtly different.

    @property (copy) return_type (^blockName) (var_type);
    

    Blocks as Parameters

    Note that this is distinct from “Blocks as Arguments”; in this instance, you’re declaring a method that wants a block argument.

    - (void)yourMethod:(return_type (^)(var_type))blockName;
    

    Blocks as Arguments

    Note that this is distinct from “Blocks as Parameters”; in this instance, you’re calling a method that wants a block argument with an anonymous block. If you have already declared a block variable, it is sufficient to pass the variable name as the argument.

    [someObject doSomethingWithBlock: ^return_type (var_type varName)
    {
        //...
    }];
    

    Anonymous Block

    This is functionally an anonymous block, however the syntax for assigning blocks to variables is simply to set the variable equal to an anonymous block.

    ^return_type (var_type varName)
    {
        //...
    };
    

    typedef Block

    This allows you to set up a short name that can be referenced just like any other class name during the declaration of blocks.

    typedef return_type (^blockName)(var_type);
    

    To then later use blockName instead of the standard block declaration syntax, simply substitute.

    Inline Block

    This is arguably a less useful utilization of blocks, but may have its place nonetheless. An inline block is an anonymous block called immediately after instantiation.

    ^return_type (var_type varName)
    {
        //...
    }(var);
    

    Inline blocks are primarily useful for scope offsetting, and are roughly equivalent to simple brace-delimited chunks of code.

    {
       //...
    }
    

    Recursive Blocks

    This allows you to call a block from itself, creating a loop that can be used during callbacks and GCD calls. This instantiation method is free of retain cycles in ARC.

    __block return_type (^blockName)(var_type) = [^return_type (var_type varName)
    {
        if (returnCondition)
        {
            blockName = nil;
            return;
        }
    
        // ...
    } copy];
    blockName(varValue);
    

    Returning Blocks

    A method can return a block,

    - (return_type(^)(var_type))methodName
    {
        // ...
    }
    

    as can a function, if a bit strangely.

    return_type (^FunctionName())(var_type)
    {
        // ...
    }
    

    Addendums

    If I’ve missed anything, please let me know in comments, and I’ll research/add them.

    Oh, and in Swift…

    blockName = (varName: var_type) -> (return_type)
    

    It’s almost like it’s a language feature.

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

Sidebar

Related Questions

What is the syntax to declare a C function that returns an Objective-C block?
Possible Duplicate: Ruby block and unparenthesized arguments I'm not sure I understand this syntax
The syntax for declaring a property referring to a block is: typedef void (^voidBlock)();
I need syntax help with the following code logic: I have a code block
In some projects that I work, was added some blocks with this syntax: var
This is related to this question I asked earlier about syntax highlighting user-defined blocks
What Javascript libraries can you recommend for syntax highlighting <code> blocks in HTML? (One
For good encapsulation, decent Objective-C programmers put their private ivars in a private extension
what is the syntax to store a block of html code to a javascript
Today I was experimenting with Objective-C's blocks so I thought I'd be clever and

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.