Wait for code to finish execution

前端 未结 2 1989
孤街浪徒
孤街浪徒 2020-12-17 01:39

I would like to know the easiest way to wait for code to finish execution within an objective c project because I am calling a webservice and retrieving the results and inst

2条回答
  •  青春惊慌失措
    2020-12-17 02:15

    You do it easily as below,

    -(void)aFunc {
    
    Do Asynchronous A job...
    
    while (A is not finished) {
    // If A job is finished, a flag should be set. and the flag can be a exit condition of this while loop
    
    // This executes another run loop.
    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
    
    }
    
    Do things using the A's result.
    
    }
    

提交回复
热议问题