在Swift之后发送的示例

时间:2015-08-04 21:31:30

标签: swift grand-central-dispatch

Xcode为Objective-C提供了 GCD:Dispatch After 代码段:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<#delayInSeconds#> * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    <#code to be executed after a specified delay#>
});

Swift的等效代码段是什么?

1 个答案:

答案 0 :(得分:10)

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (Int64)(<#delayInSeconds#> * NSEC_PER_SEC)), dispatch_get_main_queue()) {
    <#code to be executed after a specified delay#>
}

int64_t的等价物是Int64,也可以在函数调用结束时通过花括号调用块。