zoukankan      html  css  js  c++  java
  • 链式编程

    链式编程其实就两个要点:
    • Block 作为当前对象的属性。
    • Block 返回值是当前对象。
    写个特别简单的小Demo:

    .h文件

    #import <UIKit/UIKit.h>
    
    @interface SecViewController : UIViewController
    
    @property (nonatomic,copy  ) SecViewController *(^setUpBackGroundColor)(UIColor *color) ;
    
    @property (nonatomic,copy  ) SecViewController *(^setUpTitle)(NSString *title);
    
    @end
    

    .m文件

    @implementation SecViewController
    
    - (SecViewController *(^)(NSString *))setUpTitle {
        
        return ^(NSString *title) {
            
            self.title = title;
            return self;
        };
    }
    
    - (SecViewController *(^)(UIColor *))setUpBackGroundColor {
        
        return ^(UIColor *backColor) {
            
            self.view.backgroundColor = backColor;
            return self;
        };
    }
    
    @end
    

     外部调用

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
        
        SecViewController *sec = [SecViewController new];
        sec.setUpBackGroundColor([UIColor orangeColor]).setUpTitle(@"heihei");
        [self.navigationController pushViewController:sec animated:YES];
    }
  • 相关阅读:
    安装ActivePython
    安装Selenium
    安装setuptools与pip
    windows下测试环境搭建--Python安装
    编程语言 标记语言 脚本语言
    XMLHttpRequest 对象
    事务
    jsp
    Cookie案例-显示用户的上次访问时间代码实现
    事务处理
  • 原文地址:https://www.cnblogs.com/likun123/p/9560612.html
Copyright © 2011-2022 走看看