[iOS] 다운로드 작업을 위한 GCD 스케줄러 코드 실행

스케줄러 실행 코드
- (void)group{

    //1.      
    dispatch_group_t group = dispatch_group_create();

    //2.     
    dispatch_queue_t q = dispatch_get_global_queue(0, 0);

    //3.    
    //3.1   A   
    dispatch_group_enter(group);
    dispatch_async(q, ^{

        [NSThread sleepForTimeInterval:4];

        NSLog(@"Download A:     ");
        //  
        dispatch_group_leave(group);

    });

    //3.2   B   
    dispatch_group_enter(group);
    dispatch_async(q, ^{

        [NSThread sleepForTimeInterval:2];

        NSLog(@"Download B:     ");
        //  
        dispatch_group_leave(group);
    });


    //4.   ,             
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
        NSLog(@"    !!!!!!");
    });


}

실행 결과
2018-09-04 17:15:14.863894+0800 GDC     [44546:798276] Download B:     
2018-09-04 17:15:16.863463+0800 GDC     [44546:798275] Download A:     
2018-09-04 17:15:16.863914+0800 GDC     [44546:798104]     !!!!!!

좋은 웹페이지 즐겨찾기