Invoke model method with block that will run on the main thread

前端 未结 4 2039
野性不改
野性不改 2020-12-13 16:36

one of the central tenets of the architecture of my latest app is that I\'m going to call methods on the app\'s model which will be async and accept failure and success scen

4条回答
  •  爱一瞬间的悲伤
    2020-12-13 17:13

    If you are using GCD, you can use the "get main queue":

    dispatch_queue_t dispatch_get_main_queue()
    

    Call this inside an async dispatch. i.e.

    dispatch_async(dispatch_get_main_queue(), ^{
      /* Do somthing here with UIKit here */
    })
    

    The example block above could be running in an async background queue and the example code would send the UI work off to the main thread.

提交回复
热议问题