dispatch_after - GCD in Swift?

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

    Another way is to extend Double like this:

    extension Double {
       var dispatchTime: dispatch_time_t {
           get {
               return dispatch_time(DISPATCH_TIME_NOW,Int64(self * Double(NSEC_PER_SEC)))
           }
       }
    }
    

    Then you can use it like this:

    dispatch_after(Double(2.0).dispatchTime, dispatch_get_main_queue(), { () -> Void in
                self.dismissViewControllerAnimated(true, completion: nil)
        })
    

    I like matt's delay function but just out of preference I'd rather limit passing closures around.

提交回复
热议问题