在swift中翻译dispatch_async

时间:2017-01-24 16:25:19

标签: objective-c swift dispatch-async

我正在尝试将客观的c代码翻译为swift,我做到目前为止但是我得到了一些错误..任何帮助都会感激。

 dispatch_async(dispatch_get_main_queue(), ^{
        [self.window.rootViewController presentViewController:self.incomingCall animated:YES completion:nil];

在swift版本中我用这种方式做了但是我收到了一个错误:

dispatch_async(dispatch_get_main_queue(), { () -> Void in
            // Show the alert
           self.window?.rootViewController?.present(self.iincomingCall(), animated: true, completion: nil)
        })

1 个答案:

答案 0 :(得分:2)

swift 3语法是

DispatchQueue.main.async {
      //your code
 }