Edit AllPages

Blocks are declared and typed as follows:

‘return type’ (^)(‘parameter types’)

An example of a block that returns an int for two strings would be:

int (^)(NSString, NSString)

An example of a block that returns nothing from no arguments would be:

void (^)(void)

Blocks can also be declared as local variables in Objective-C code like so:

int main(int argc, string[] *argv) { int(^x)(int input) = ^(int input){ return input * input; };

int sixteen = x(4); }

*The original message announcing blocks to the Clang list: *Blocks on the Clang site: *MikeAsh’s introduction: *A backport of blocks for Leopard and iPhoneOS: *A guide to using blocks in C and Objective-C:

Ok but is it very different then callback function ? —- Yes, blocks capture their parent function’s scope, and can even access it after the parent function has returned. See