Created
May 8, 2018 05:55
-
-
Save zhangkn/f563193f99617e38218d03d2e60e9f08 to your computer and use it in GitHub Desktop.
People
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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