且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Swift中,如何在GCD主线程上调用带有参数的方法?

更新时间:2023-02-24 16:10:24

只需将其写在completion handler中.无需使用dispatch_after

Just write this in completion handler.No need to use dispatch_after

dispatch_async(dispatch_get_main_queue(), {
  let delegateObj = UIApplication.sharedApplication().delegate as YourAppDelegateClass
  delegateObj.addUIImage("yourstring")
})

快速3/4:

DispatchQueue.main.async { 
  let delegateObj = UIApplication.sharedApplication().delegate as YourAppDelegateClass
  delegateObj.addUIImage("yourstring")
}

还用于在主队列上发送后

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
  // your code here
}

用您的委托类替换YourAppDelegateClass