I know that an Objective-C Block can capture and set the value of variables outside of its enclosing scope. How does it do that?
Basically, the block "object" contains an variable inside the block object (like an "instance variable" of the block object) for every captured local variable. (Josh Caswell's answer provides more details about how it is implemented.) When the block is created, the value of each captured local variable at that time is copied into the corresponding variable inside the block. Whenever the variable is used inside the block, it uses this variable inside the block instead.