Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 781 Bytes

objc-block-syntax.md

File metadata and controls

39 lines (29 loc) · 781 Bytes
layout title description redirect_from
default
Objective-C guide: block syntax
A quick reference guide for block syntax in Objective-C.
/fuckingblocksyntax/
/goshdarnblocksyntax/

As a local variable

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

As a property

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

As a method parameter

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

As an argument to a method call

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

As a typedef

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