dispatch_after - GCD in Swift?

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

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // ...
    });
    

    The dispatch_after(_:_:_:) function takes three parameters:

    a delay
    a dispatch queue
    a block or closure

    The dispatch_after(_:_:_:) function invokes the block or closure on the dispatch queue that is passed to the function after a given delay. Note that the delay is created using the dispatch_time(_:_:) function. Remember this because we also use this function in Swift.

    I recommend to go through the tutorial Raywenderlich Dispatch tutorial

提交回复
热议问题