快速延迟功能

编程入门 行业动态 更新时间:2024-10-28 07:34:17
本文介绍了快速延迟功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我没有代码样本或任何东西,因为我不知道该怎么做,但是有人能告诉我如何在一段时间内用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() })

更多推荐

快速延迟功能

本文发布于:2023-11-26 04:37:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632650.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:快速   功能

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!