欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

iOS 链式编程思想

程序员文章站 2022-07-12 16:32:11
...

链式编程思想不用啰嗦哈,

例如将计算方法,用链方式串联起来,实现可以参考下

github:  RAC_链式编程

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    int iResult = [NSObject makeCaculators:^(CaculatorMaker *make) {
        
        make.add(1).add(2).add(3).divide(2);
        
    }];
    
    NSLog(@" 1===== %d",iResult);
    
    CaculatorMaker *maker = [[CaculatorMaker alloc]init];
    
    NSInteger reslut =
    [[[maker caculator:^int(int result) {
        result += 2;
        result *= 5;
        return result;
        
    }] equle:^BOOL(int result) {
        
        return result = 10;
        
    }] isEqule];
    
    
    NSLog(@" 2===== %ld",(long)reslut);
}

注:

reactiveCocoa的常用语法

github: reactiveCocoa