#import <Foundation/Foundation.h>
void myBLock() {
__block int num = 5;
void (^myBlockInternal)(void) = ^{
num = 6;
NSLog(@"%d", num);
};
myBlockInternal();
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
myBLock();
}
return 0;
}
输出
2018-08-13 12:00:14.264296+0800 Block[43795:1488802] 6
2018-08-13 12:00:14.264494+0800 Block[43795:1488802] Hello, World!
Program ended with exit code: 0