Ios 将参数传递给dispatch\u async
我是Swift的新手,了解dispatch_async函数是如何工作的。API文档显示dispatch\u async有两个参数。然而,我能够通过一个论点,这是好的Ios 将参数传递给dispatch\u async,ios,swift,ios8,grand-central-dispatch,dispatch-async,Ios,Swift,Ios8,Grand Central Dispatch,Dispatch Async,我是Swift的新手,了解dispatch_async函数是如何工作的。API文档显示dispatch\u async有两个参数。然而,我能够通过一个论点,这是好的 dispatch_async(dispatch_get_main_queue()) { } 为什么我不需要传入两个参数 谢谢,, API文件: 这是一种尾随闭包语法 func someFunctionThatTakesAClosure(closure: () -> ()) { // function body
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
}
这就是异步调度的样子
dispatch_async(dispatch_get_main_queue(), ^{
});
此部分
^{
}
是函数的第二个参数,它是用于回调实现的匿名代码块