[Code Note] iOS-Modify the external variable value in the Block, ios-block
I. Code.
-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // The first is to modify the static global variable, and the second is to modify the variable modified with the New Keyword _ block. _ Block int blockLocal = 100; static int staticLocal = 100; void (^ aBlock) (void) = ^ (void) {blockLocal ++; staticLocal ++ ;}; NSLog (@ "---- blockLocal -- % d", blockLocal); NSLog (@ "--- staticLocal -- % d", staticLocal); aBlock (); NSLog (@ "---- blockLocal -- % d", blockLocal); NSLog (@ "--- staticLocal -- % d", staticLocal );}
2. output.
13:15:30. 598 modify the value of the external variable in the Block [7561: 195731] ---- blockLocal -- 1002015-10-23 13:15:30. 598 modify the value of the external variable in the Block [7561: 195731] --- staticLocal -- 1002015-10-23 13:15:30. 598 modify the value of the external variable in the Block [7561: 195731] ---- blockLocal -- 1012015-10-23 13:15:30. 598 modify the value of the external variable in the Block [7561: 195731] --- staticLocal -- 101