方法调用顺序

//    __block int count = 0; 
    void (^block)(void) = ^(void){
        int i = 0;
//        [_container class];  // 当使用__strong类型修饰的变量,block 会从代码区拷贝到堆区
        do {
            NSLog(@"5");
//            count ++;
            i ++;
        } while (i < 5);
     
    };
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), block);
    
    dispatch_async(dispatch_get_main_queue(), ^{
        int i = 0;
        do {
            NSLog(@"4");
            i ++;
        } while (i < 5);
    });
    
    [self test1];
    [self performSelector:@selector(test2)];
    int i = 0;
    do {
        [self performSelector:@selector(test3) withObject:nil afterDelay:0.0];
        i ++;
    } while (i < 5);
    
    void (^blockAsycn)(void) = ^(void) {
    
        NSLog(@"6");
    };
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), blockAsycn);
    
    
    for (int i = 0; i < 5; i ++) {
        [self test1];
    }
    ```

![运行结果](http://upload-images.jianshu.io/upload_images/32940-c72ac708de1ac754.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

/**
总结:
1. 不同种调用方式,他们的方法是存储在各自的区域,且是有调用优先级的(主线程顺序调用)
2. 异步的方式,不受区域的限制,在同等优先级的情况下,受顺序控制
3. block块的内容,会先拷贝到堆(如果强引用的对象(连__block 的c类型也会)在block中)这里的block都是NSGlobalBlock,也就是代码区
**/

你可能感兴趣的:(方法调用顺序)