Block access the data in normal way as the other normal function do. Block can access any class variable or function variable out side it but cannot modified it.
int x= 111;
void (^printXAndY)(int) = ^(int y) {
printf("%d %d\n", x, y);
};
printXAndY(333);
output will be :
111 333
But if you try to assing the new value to variable x. then it will not change the value. For example
int x= 111;
void (^printXAndY)(int) = ^(int y) {
x=x+y
printf("%d %d\n", x, y); // error here
};
so if you want change the value then you can user __block before the variable. for example
_block int x=111;
then it upper block will the expected result. And it will add the both variable.
111+333=444.
0 Comment(s)