利用block实现链式编程
@interface Person : NSObject
- (Person *(^)(NSString *name))study;
- (Person *(^)())run;
@end
#import "Person.h"
@implementation Person
- (Person *(^)(NSString *))study
{
return ^(NSString *name){
NSLog(@"study----%@", name);
return self;
};
}
- (Person *(^)())run
{
return ^{
NSLog(@"run----");
return self;
};
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool {
Person *p = [[Person alloc] init];
p.study(@"xx宝典").run().study(@"xx剪发");
}
return 0;
}