Delay using DispatchTime.now() + float?

前端 未结 3 1985
南方客
南方客 2020-12-17 08:30

What exactly is going on with DispatchTime.now()

How come I can\'t assign the time to wait as a variable?

And How Could I use a variable ?

3条回答
  •  感动是毒
    2020-12-17 09:28

    You can use DispatchTimeInterval to add time in DispatchTime.

    For Example :

    let whenWhen = DispatchTime.now() + DispatchTimeInterval.seconds(time)
    DispatchQueue.main.asyncAfter(deadline: whenWhen){
    
        print("Hello")
    
    }
    

提交回复
热议问题