When bringing externally declared variables into a block...
Using the __block
directive captures a variable by reference...
Variables local to the enclosing lexical scope declared with the __block storage modifier are provided by reference and so are mutable. Any changes are reflected in the enclosing lexical scope, including any other blocks defined within the same enclosing lexical scope.
Without the variable is captured by value...
Local variables declared within the lexical scope of the block, which behave exactly like local variables in a function. Each invocation of the block provides a new copy of that variable. These variables can in turn be used as const or by-reference variables in blocks enclosed within the block.
I've heard it said that using the __block is less efficient, but how is this possible? Won't you always avoid a costly copy?