新浪微博客户端(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 0;
}

运行结果:

2016-12-19 22:18:34.247 block的使用[2334:101201] study
2016-12-19 22:18:34.248 block的使用[2334:101201] run
Program ended with exit code: 0

 

posted @ 2016-12-19 22:22  夜行过客  阅读(249)  评论(0编辑  收藏  举报