Does dispatch_async(dispatch_get_main_queue(), ^{…}); wait until done?

后端 未结 8 1707
一整个雨季
一整个雨季 2020-11-28 20:45

I have a scenario in my app, where I want to do some time consuming task which consists of some data processing as well as UI update, in a method. My method looks like this,

8条回答
  •  佛祖请我去吃肉
    2020-11-28 21:14

    dispatch_queue_t queue = dispatch_queue_create("com.example.MyQueue", NULL);
    dispatch_async(queue, ^{
      // Do some computation here.
    
      // Update UI after computation.
      dispatch_async(dispatch_get_main_queue(), ^{
        // Update the UI on the main thread.
      });
    });
    

提交回复
热议问题