使用Xcode 6.4在Swift中重复x次的函数

时间:2015-07-30 15:57:26

标签: xcode swift

我有一个使用3个函数的应用程序,这些函数使用NSTimer连续调用或一个接一个调用。我希望这些函数重复x次,因为我有一个名为repsField的@IBOutlet,它创建一个存储在全局变量repetitions中的值,该值默认设置为0,直到用户使用@IBOutlet更改此值。

基本上,我希望将全局变量repetitions调用函数的次数相乘。我怎么能这样做?

屏幕截图:

enter image description here

以下是其中一个计时器的示例......

func start1() {
    if timerRunning==false{ // Timer will start
        timer=NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("Counting1"), userInfo: nil, repeats: true)
        timerRunning=true
    }
}

func Counting1(){
    timerCount+=1 timerLabel.text="\(timerCount) secs"
    if timerRunning==true && timerCount >= timerMaximum {
        stop()
        intervalAlert()
        start2()
    }
}

请尽快回复我

1 个答案:

答案 0 :(得分:1)