dispatch_after - GCD in Swift?

前端 未结 25 2446
心在旅途
心在旅途 2020-11-21 06:07

I\'ve gone through the iBook from Apple, and couldn\'t find any definition of it:

Can someone explain the structure of dispatch_after?

d         


        
25条回答
  •  醉梦人生
    2020-11-21 06:37

    Apple has a dispatch_after snippet for Objective-C:

    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#>
    });
    

    Here is the same snippet ported to Swift 3:

    DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + <#delayInSeconds#>) {
      <#code to be executed after a specified delay#>
    }
    

提交回复
热议问题