Passing an argument to dispatch_async

时间秒杀一切 提交于 2019-12-02 04:15:34

It is a trailing closure syntax

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

Apple_iOS0304

This is how the dispatch_async looks like..

dispatch_async(dispatch_get_main_queue(), ^{

});

this part

^{

}

is the second parameter to your function, which is an anonymous code block used for callBack implementation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!