链式编程思想

链式编程思想_第1张图片
[view mas_makeConstraints:^(MASConstraintMaker *make) {
    
    make.top.left.equalTo(@10);
    make.right.bottom.equalTo(@-10);
    
}];

int result = [self tmf_calculate:^(CalcalateManager *mgr){
    
    mgr.add(5).add(6);
    
}];

NSLog(@"result:%d",result);
  #import "NSObject+Calculate.h”
  #import “CalcalateManager.h"
@implementation NSObject (Calculate)

-(int)tmf_calculate:(void(^)())block{
    // 创建计算管理者
    CalcalateManager *mgr = [[CalcalateManager alloc] init];
    // 执行计算
    block(mgr);
    return mgr.result;
}
#import 

@interface CalcalateManager : NSObject
@property(nonatomic, assign) int result;

- (CalcalateManager *(^)(int))add;

@end


#import "CalcalateManager.h"

@implementation CalcalateManager

- (CalcalateManager *(^)(int))add{
    
    return ^(int value){
        
        _result += value;
        return self;
        
    };
    
}

@end

你可能感兴趣的:(链式编程思想)