March 2012
Intermediate to advanced
590 pages
22h 48m
English
There is one special characteristic of blocks that makes them very useful: they capture variables.
A block, like a function, can use the arguments passed to it and can declare local variables. Modify the block in BNRAppDelegate.m’s application:didFinishLaunchingWithOptions: so that it declares and uses a local variable.
[executor setEquation:^int(int x, int y) {
int sum = x + y;
return x + y;
return sum;
}];
The variable sum is local to the block, so sum can be used inside this block. Both x and y are arguments of the block, so they, too, can be used inside this block.
A block can also use any variables that are visible ...
Read now
Unlock full access