ios - 将参数传递给 dispatch_async

标签 ios swift ios8 grand-central-dispatch dispatch-async

我是 Swift 的新手,正在研究 dispatch_async 函数的工作原理。 API 文档显示 dispatch_async 有两个参数。但是,我可以传递一个参数,这没关系。

dispatch_async(dispatch_get_main_queue()) { 

}

为什么我不需要传入两个参数?

谢谢,

API 文档:

enter image description here

最佳答案

这是一个尾随闭包语法

func someFunctionThatTakesAClosure(closure: () -> ()) {
    // function body goes here
}

// here's how you call this function without using a trailing closure:

someFunctionThatTakesAClosure({
    // closure's body goes here
})

// here's how you call this function with a trailing closure instead:

someFunctionThatTakesAClosure() {
    // trailing closure's body goes here
}

https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html

关于ios - 将参数传递给 dispatch_async,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29138781/

相关文章:

ios - 快速禁用 WKWebview 中的 Youtube 应用程序重定向

swift - UIView.animate - 将 .autoreverse 与其他选项一起使用

ios - iOS-检测软件键盘高度

ios - iPad 应用程序的自定义数字键盘

xcode - 无法在 iOS8beta5 中使用 UIWebView 打开 PDF 文件

ios - 如何为每个 UICollectionViewCell 设置不同的高度

ios - 是在旧设备上忽略 openGL 效果更好,还是接受 slooooow 性能?

c# - Xamarin C# 一个 UITableView 中的两个 UITableViewCells

ios - 使用 VNCoreMLRequest 一次检测多个对象?

ios - 如何在tableview单元ios swift中获取accessoryView框架的框架