在触摸开始函数中使用 NSTimer 时出现信号 sigbart 错误

signal sigbart error when using NSTimer within a touches began function

我正在尝试构建一个应用程序,当第一次触摸屏幕时它会启动一个 NSTimer,但是在 touches 开始函数中使用 NSTimer 我得到一个 signal sigbart 错误。如果有人有任何替代方法可以用来获得相同的结果,我将不胜感激。

这是我当前的基本代码

    var condition = 0

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

    if(condition == 1) {
    timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("timerUpdate"), userInfo: nil, repeats: true)
    }

    cat.physicsBody?.velocity = CGVectorMake(0, 0)
    cat.physicsBody?.applyImpulse(CGVectorMake(0, 1))


}

您必须为选择器添加函数 timerUpdate

 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    if(condition == 1) {
        timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("timerUpdate"), userInfo: nil, repeats: true)
    }

    cat.physicsBody?.velocity = CGVectorMake(0, 0)
    cat.physicsBody?.applyImpulse(CGVectorMake(0, 1))
}

func timerUpdate(){
    print("timerUpdate")
}