^{
NSLog(@"This is a block");
}
void (^simpleBlock)(void) = ^{
NSLog(@"This is a block");
};
...
simpleBlock();
typedef returnType (^blockName)(parameterTypes);
Example: Objective-C:
typedef int (^stringToIntBlock)(NSString *);
returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};
int (^calcSum)(int,int);
^(int value1, int value2) {
return (value1 + value2);
}
int (^calcSum)(int, int) = ^(int value1, int value2) {
return value1 + value2;
};
int total = calcSum(2, 5);
// total = 5