简体   繁体   English

在Swift 2中使用NSTimer.scheduledTimerWithTimeInterval

[英]Using NSTimer.scheduledTimerWithTimeInterval in Swift 2

I need to call a function [calculatePower(day)] every Xth of a second as in 我需要每X秒调用一个函数[calculatePower(day)],如下所示:

for day = 1...365 {
    calculatePower(day)
}

What is the current best practice to do this? 目前的最佳做法是什么?

您可以这样做(每1/10秒):

NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: #selector(youFuncHere), userInfo: nil, repeats: true)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift Playground 中的 NSTimer.scheduledTimerWithTimeInterval - NSTimer.scheduledTimerWithTimeInterval in Swift Playground Swift如何防止多个NSTimer.scheduledTimerWithTimeInterval - Swift how to prevent multiple NSTimer.scheduledTimerWithTimeInterval 什么是 swift 3 中 NSTimer.scheduledTimerWithTimeInterval() 的替换? - What is replacement of NSTimer.scheduledTimerWithTimeInterval() in swift 3? 如何在swift中暂停和恢复NSTimer.scheduledTimerWithTimeInterval? - How can I pause and resume NSTimer.scheduledTimerWithTimeInterval in swift? Swift,XCode:有没有办法将变量用作NSTimer.scheduledTimerWithTimeInterval Int? - Swift, XCode: Is there a way to use a variable as a NSTimer.scheduledTimerWithTimeInterval Int? Swift的NSTimer.scheduledTimerWithTimeInterval的两个参数集 - Two parameter sets for Swift's NSTimer.scheduledTimerWithTimeInterval NSTimer.scheduledTimerWithTimeInterval()具有可变延迟 - NSTimer.scheduledTimerWithTimeInterval() with variable delay 如何停止NSTimer.scheduledTimerWithTimeInterval - How to stop NSTimer.scheduledTimerWithTimeInterval 当按下主页按钮时,如何在spritekit [SWIFT]中暂停和重新启动NSTimer.scheduledTimerWithTimeInterval? - How to pause and restart NSTimer.scheduledTimerWithTimeInterval in spritekit [SWIFT] when home button is pressed? 无法识别的选择器使用NSTimer.scheduledTimerWithTimeInterval函数发送到实例 - Unrecognized selector sent to instance with NSTimer.scheduledTimerWithTimeInterval function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM