How Do I Declare A Block in Objective-C?

How Do I Declare A Block in Objective-C?

I thought to share here. so that along with me it would be helpful to others too. As a local variable : As a property : As a method parameter : As an argument to a method call :...

Alok Choudhary
Austin, TX
1 min read

I thought to share here. so that along with me it would be helpful to others too.

As a local variable:

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

As a property:

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

As a method parameter:

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

 

As an argument to a method call:

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

As a typedef:

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

Link copied to clipboard!

Made with ❤️ in Austin.

Copyright © 2026