- Block 作为当前对象的属性。
- Block 返回值是当前对象。
#import <UIKit/UIKit.h>
@interface SecViewController : UIViewController
@property (nonatomic,copy ) SecViewController *(^setUpBackGroundColor)(UIColor *color) ;
@property (nonatomic,copy ) SecViewController *(^setUpTitle)(NSString *title);
@end
@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];
}
如果看不懂自己敲一遍就懂了。