新浪微博客户端(63)-使用block进行链式编程

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:
上一篇:Subversion Edge


下一篇:Asp.net MVC 搭建属于自己的框架(一)