块对象block小结(2)

MRC环境下

//
//  main.m
//  blcok
//
//  Created by ios on 16/4/6.
//  Copyright © 2016年 ios. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <Block.h>
void (^g)(void) = NULL;
int c = 1 ;
void func(int n){
    __block int sh = 0;
    void (^b1)(void) = ^{
        sh +=1;
        printf("%d:b1,n = %d, sh= %d\n",++c,n,sh);
    };
    void (^b2)(void) = ^{
        sh+=20;
        printf("%d:b1,n = %d, sh= %d\n",++c,n,sh);
    };
    b1();
    b2();
    g = Block_copy(b1);
    sh+=n*1000;
    n =999;
    b2();

}

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        void (^myblock)(void);
        func(1);
        myblock =g ;
        myblock();
        func(2);
        myblock();
        Block_release(g);
        Block_release(myblock);

}
    return 0;
}

块对象block小结(2)

上一篇:Java访问Redis


下一篇:hdu 4597 Play Game 区间dp