gpt4 book ai didi

ios - 将参数传递给 dispatch_async

转载 作者:搜寻专家 更新时间:2023-11-01 06:47:15 26 4
gpt4 key购买 nike

我是 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com