iOS Block Modify captured variable

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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.
};


Got any iOS Question?