https://www.cnblogs.com/chzheng/p/5949376.html
Functional Programming
,简写 FP
自由组合
block
/闭包
Masnory
/ SnapKit
make.centerY.equalTo(self.view).offset(100);
@interface Person : NSObject - (void)eat; - (void)run; @end @implementation Person - (void)eat { NSLog(@"吃"); } - (void)run { NSLog(@"跑"); } @end
Person *p = [[Person alloc] init]; [p run]; [p eat];
- (Person *)eat1 { NSLog(@"吃1"); return self; } - (Person *)run1 { NSLog(@"跑1"); return self; }
[[person eat1] run1];
- (Person * _Nonnull (^)())eat2 { Person * (^myEatBlock)() = ^ Person * () { NSLog(@"吃2"); return self; }; return myEatBlock; } - (Person * _Nonnull (^)())run2 { return ^ Person * { NSLog(@"跑2"); return self; }; }
person.eat2().run2(); person.run2().eat2();
- (Person * _Nonnull (^)(NSString * _Nonnull))eat3 { return ^ Person * (NSString * food) { NSLog(@"吃 %@", food); return self; }; } - (Person * _Nonnull (^)(float))run3 { return ^ Person * (float distance) { NSLog(@"跑了 %f 米", distance); return self; }; }
p.run3(100).eat3(@"food"); 简单的实际运用可以参考 我的这篇文章