首页 > 代码库 > 新浪微博客户端(63)-使用block进行链式编程

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

 

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