Person.h
#import <Foundation/Foundation.h> @interface Person : NSObject - (Person *(^)())study; - (Person *(^)())run; @end
Person.m
#import "Person.h" @implementation Person - (Person *(^)())study { return ^{
NSLog(@"study");
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.study().run(); }
return ;
}
运行结果:
-- ::34.247 block的使用[:] study
-- ::34.248 block的使用[:] run
Program ended with exit code: