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的等效代码段是什么?
答案 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
,也可以在函数调用结束时通过花括号调用块。