dispatch_after - GCD in Swift?

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

    Simplest solution in Swift 3.0 & Swift 4.0 & Swift 5.0

    func delayWithSeconds(_ seconds: Double, completion: @escaping () -> ()) {
        DispatchQueue.main.asyncAfter(deadline: .now() + seconds) { 
            completion()
        }
    }
    

    Usage

    delayWithSeconds(1) {
       //Do something
    }
    

提交回复
热议问题