August 2011
Intermediate to advanced
552 pages
23h 48m
English
Let’s revisit variable capture. Each of the blocks here is the same code, but they are “created” at different times – each after the value of val has changed.
typedef void (^BoringBlock) (void);
int val = 23;
BoringBlock block1 = ^{ NSLog (@"%d", val); };
val = 42;
BoringBlock block2 = ^{ NSLog (@"%d", val); };
val = 17;
BoringBlock block3 = ^{ NSLog (@"%d", val); };
block1 points to a block that has captured val when it had a value of 23. block2 points to a block that has captured val when it had a value of 42, and likewise ...
Read now
Unlock full access