zoukankan      html  css  js  c++  java
  • 新浪微博客户端(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
  • 相关阅读:
    数组与指针
    壁纸
    2019/1/11
    指针A
    数组B
    一起来抓老鼠啊!快乐呀!
    打印沙漏
    I think I need a boat house
    币值转换
    《C语言程序设计》编程总结汇总
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6200825.html
Copyright © 2011-2022 走看看