首页 > 代码库 > IOS_Block_使用
IOS_Block_使用
int main(int argc, const char * argv[]) { @autoreleasepool { //first void (^myBlock)() = ^{ NSLog(@"myBlock execute"); }; myBlock(); //second return value int (^sum)(int, int) = ^int(int x, int y){ return x+y; }; NSLog(@"sum = %d", sum(2, 6)); //third Calc *c = [[Calc alloc] init]; NSLog(@"s = %d", [c calcNum1:10 withNum2:20 andCalcWith:sum]); NSLog(@"value = http://www.mamicode.com/%d", [c calcNum1:10 withNum2:30 andCalcWith:^int(int x, int y) {>// // Calc.h // #import <Foundation/Foundation.h> typedef int (^calcBlock)(int, int); @interface Calc : NSObject -(int) calcNum1:(int)num1 withNum2:(int)num2 andCalcWith:(calcBlock)calc; @end// // Calc.m // #import "Calc.h" @implementation Calc - (int)calcNum1:(int)num1 withNum2:(int)num2 andCalcWith:(calcBlock)calc { return calc(num1, num2); } @end
IOS_Block_使用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。