Swift 4/5 实现GCD的dispatch_after

时间:2022-06-01 12:41:39

Swift 4实现延时的简单方法:

DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) {
// Code
}

Swift 5实现延时的简单方法:

DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
// code to execute
})