Skip to content

Instantly share code, notes, and snippets.

@zhangkn
Created May 8, 2018 05:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangkn/f563193f99617e38218d03d2e60e9f08 to your computer and use it in GitHub Desktop.
Save zhangkn/f563193f99617e38218d03d2e60e9f08 to your computer and use it in GitHub Desktop.
People
#import <Foundation/Foundation.h>
#import "People.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
//使用block实现链式编程
People *p= [[People alloc]init];
// p.run() <=> [p run]();
p.run().study();
p.run().name(@"将block和method的特性 结合起来");
}
return 0;
}
@interface People : NSObject
- (People *(^)())run;
- (People *(^)())study;
- (People *(^)(NSString* name))name;
@end
@implementation People
- (People *(^)())run{
return ^{
NSLog(@"run");
return self;
};// 返回一个block
}
- (People *(^)())study{
return ^{
NSLog(@"study");
return self;
};// 返回一个block
}
- (People *(^)(NSString *))name{
return ^(NSString *name){
NSLog(@"%@",name);
return self;
};
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment