xcode 尝试使用主线程时 DispatchQueue 的歧义使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39644492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:19:52  来源:igfitidea点击:

Ambiguous use of DispatchQueue on trying to use main thread

swiftxcodemultithreadingswift3xcode8

提问by Jonathan Bursztyn

This is a weird issue and I can't seem to find any help. On Swift 3, trying to make a call on the main thread I try to use DispatchQueue.main.async, but it doesn't compile.

这是一个奇怪的问题,我似乎找不到任何帮助。在 Swift 3 上,尝试在主线程上调用我尝试使用 DispatchQueue.main.async,但它无法编译。

Any ideas would be helpful.

任何想法都会有所帮助。

enter image description here

在此处输入图片说明

回答by Rashwan L

Try this code instead, this is the Swift 3.0 syntax:

试试这个代码,这是 Swift 3.0 语法:

DispatchQueue.main.async(execute: { () -> Void in

})

For Swift 4.x you can also use:

对于 Swift 4.x,您还可以使用:

DispatchQueue.main.async {

}