Modify captured variable

suggest change

Block will capture variables that appeared in the same lexical scope. Normally these variables are captured as “const” value:

int val = 10;
void (^blk)(void) = ^{
    val = 20; // Error! val is a constant value and cannot be modified!

In order to modify the variable, you need to use the __block storage type modifier.

__block int val = 10;
void (^blk)(void) = ^{
    val = 20; // Correct! val now can be modified as an ordinary variable.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents