// gloabString = @"gloabString";
// NSLog(@"init == %@",gloabString);
// typedef void(^myBlock) (int a);
// myBlock block = ^(int m){
// NSLog(@"%d",m);
// gloabString = @"changeGloabString";
// NSLog(@" in %@",gloabString);
// };
// NSLog(@"pro == %@",gloabString);
// block(10);
// NSLog(@" out %@",gloabString);
/**
init == gloabString
pro == gloabString
10
in changeGloabString
out changeGloabString
*/
全局变量、静态变量 ?要看看内存的事情哦,你就会理解了
// NSString partString = @"partString";
// NSLog(@"init partString %@",partString);
// typedef void(^myBlock) (int a);
// myBlock block = ^(int m){
// NSLog(@"partString %@",partString);
// };
// partString = @"changePartString";
// NSLog(@"partString 1 %@",partString);
// block(10);
// NSLog(@"partString 2 %@",partString);
// /*
// init partString partString
// partString 1 changePartString
// partString partString
// partString 2 changePartString
// */
__block NSString blockString = @"blockString";
NSLog(@"init Value %@",blockString);
typedef void(^myBlock) (int a);
myBlock block = ^(int m){
blockString = @"changeBlockString";
NSLog(@"blockString in %@",blockString);
};
NSLog(@"blockString out1 %@",blockString);
block(111);
NSLog(@"blockString out2 %@",blockString);
/*
init Value blockString
blockString out1 blockString
blockString in changeBlockString
blockString out2 changeBlockString
*/
网友评论