本文介绍了快速延迟功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我没有代码样本或任何东西,因为我不知道该怎么做,但是有人能告诉我如何在一段时间内用swift延迟函数吗?
$您可以使用GCD(例如延迟10秒):Swift 2:
let triggerTime =(Int64(NSEC_PER_SEC)* 10) dispatch_after(dispatch_time(DISPATCH_TIME_NOW,triggerTime) ,dispatch_get_main_queue(),{() - >无效 self.functionToCall()})Swift 3:
DispatchQueue.main.asyncAfter(截止日期:.now()+ 10.0,执行:{ self.functionToCall()})
I don't have a code to sample or anything, because I have no idea how to do it, but can someone please tell me how to delay a function with swift for a set amount of time?
解决方案You can use GCD (in the example with a 10 second delay):
Swift 2:
let triggerTime = (Int64(NSEC_PER_SEC) * 10) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, triggerTime), dispatch_get_main_queue(), { () -> Void in self.functionToCall() })Swift 3:
DispatchQueue.main.asyncAfter(deadline: .now() + 10.0, execute: { self.functionToCall() })
更多推荐
快速延迟功能
发布评论