我是 Swift 的新手,正在研究 dispatch_async 函数的工作原理。 API 文档显示 dispatch_async 有两个参数。但是,我可以传递一个参数,这没关系。
dispatch_async(dispatch_get_main_queue()) {
}
为什么我不需要传入两个参数?
谢谢,
API 文档:
最佳答案
这是一个尾随闭包语法
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
}
关于ios - 将参数传递给 dispatch_async,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29138781/