在block内部更改外部的变量

saonian 发布于 18-08-13 12:01 已修改 594 点击
```oc #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; } ``` 输出 ```bash 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 ```
0 评论

请登录后发表评论

saonian

all or nothing, now or never.

文章
回复
粉丝