Mulithreading: executing method calls only after finished executing other method

后端 未结 2 1836
春和景丽
春和景丽 2021-02-04 20:53

I am trying to process method asynchronously, as per requirements, once the first method has completed, only then the second method should start executing. The Problem is first

2条回答
  •  逝去的感伤
    2021-02-04 21:40

    You can use a completion block. You just need to modify firstMethod this way:

    - (void)firstMethodWithOnComplete:(void (^)(void))onComplete {
          dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
              //processing here.....
              onComplete();
           });
    }    
    

    And then use it this way:

    [self firstMethodWithOnComplete:^{
        [self secondMethod];
    }];
    

提交回复
热议问题