dispatch_after - GCD in Swift?

前端 未结 25 2398
心在旅途
心在旅途 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:25

    In Swift 5, use in the below:

     DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: closure) 
    
    // time gap, specify unit is second
    DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2)) {
                Singleton.shared().printDate()
            }
    // default time gap is second, you can reduce it
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
              // just do it!
        }
    

提交回复
热议问题