// Person.h
#import <Foundation/Foundation.h>
@interface Person : NSObject
//- (Person *)study;
//- (Person *)run;
- (Person *(^)(NSString *name))study;
- (Person *(^)())run;
@end
// Person.m
#import "Person.h"
@implementation Person
//- (Person *)study
//{
// NSLog(@"study----");
//
// return self;
//}
//
//- (Person *)run
//{
// NSLog(@"run----");
// return self;
//}
- (Person *(^)(NSString *))study
{
return ^(NSString *name){
NSLog(@"study----%@", name);
return self;
};
}
- (Person *(^)())run
{
return ^{
NSLog(@"run----");
return self;
};
}
@end
// main.m
#import <Foundation/Foundation.h>
#import "Person.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
Person *p = [[Person alloc] init];
// [p run];
// [p study];
// [[p run] study];
// [[[[p run] study] run] study];
p.study(@"Math").run().study(@"English");
}
return 0;
}
网友评论