标签:
- (void)viewDidLoad { [super viewDidLoad]; //block void(^myBlock)(void) = ^(void) { NSLog(@"This is a block without parameter and returned value"); }; myBlock(); }
- (void)viewDidLoad { [super viewDidLoad]; //block void(^myBlock)(void) = ^ { NSLog(@"This is a block without parameter and returned value"); }; myBlock(); }
-(void)blockWithParameterButNoReturnData { void(^myBlock)(int) = ^(int num) { NSLog(@"%d",num*100); }; myBlock(4); }
-(void)blockWithParameterAndReturnValue { int (^myBlock)(int) = ^(int num) { return num * 100; }; int result = myBlock(2); NSLog(@"This is a block with parameter and return value :%d",result); }
-(void)testBlock { void(^blockOne)(void) = ^ { NSLog(@"This is block one"); }; int c = 10; void(^blockTwo)(void) =^(void) { NSLog(@"This is a block two %d",c); }; void(^blockThree)(void) =[blockTwo copy]; NSLog(@"blockOne address is :%@",blockOne); NSLog(@"blockTwo address is :%@",blockTwo); NSLog(@"blockThree address is :%@",blockThree); }
标签:
原文地址:http://www.cnblogs.com/zhanggui/p/4656440.html