【问题标题】:Wait After While Loop等待While循环
【发布时间】:2015-07-18 14:45:48
【问题描述】:

我有一个循环太快了,所以我想让它每秒左右发生一次。我现在有这个:

while (i == 1, ) {
    println("printed")
}

【问题讨论】:

标签: swift


【解决方案1】:

您可以使用NSTimer 并每秒安排一个操作:

NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "yourMethodToCall", userInfo: nil, repeats: true)

func yourMethodToCall(){
    println("each second")
}

【讨论】:

    猜你喜欢
    • 2021-08-14
    • 2012-10-13
    • 2012-05-20
    • 2010-12-26
    • 1970-01-01
    • 1970-01-01
    • 2012-12-09
    • 2016-12-05
    • 2016-07-22
    相关资源
    最近更新 更多