Changing Enclosing Scope
Blocks can also change their enclosing scope. Say you want to count the number of badgers found inside of the list of words. You want the flexibility of providing subString to the block, but you also want a way for multiple invocations of the block to calculate a value and let the enclosing scope know about that value. A return value from the block will not work here because the badger count is calculated across an arbitrary number of block invocations. You cannot use a captured variable because they are const.
__block, with two leading underscores, is a new compiler keyword introduced to indicate that an enclosing scope variable can be modified from inside of the block.
Here is an enumeration that counts the number ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access