Objective-C LanguageBlocks


  • // Declare as a local variable:

    returnType (^blockName)(parameterType1, parameterType2, ...) = ^returnType(argument1, argument2, ...) {...};

  • // Declare as a property:

    @property (nonatomic, copy, nullability) returnType (^blockName)(parameterTypes);

  • // Declare as a method parameter:

    - (void)someMethodThatTakesABlock:(returnType (^nullability)(parameterTypes))blockName;

  • // Declare as an argument to a method call:

    [someObject someMethodThatTakesABlock:^returnType (parameters) {...}];

  • // Declare as a typedef:

    typedef returnType (^TypeName)(parameterTypes);

    TypeName blockName = ^returnType(parameters) {...};

  • // Declare a C function return a block object:

    BLOCK_RETURN_TYPE (^function_name(function parameters))(BLOCK_PARAMETER_TYPE);


Blocks are specified by the Language Specification for Blocks for C, Objective-C, C++ and Objective-C++.

Additionally, the Blocks ABI is defined by the Block Implementation Specification.

Related Examples