Ios 如何使NSTimer在满足条件后停止重复

Ios 如何使NSTimer在满足条件后停止重复,ios,swift,nstimer,Ios,Swift,Nstimer,我有两个NSTimer,我对它们进行了编程,使一个按钮出现在屏幕上,然后消失。我如何编程使其在满足条件后停止添加和删除按钮 这是我的密码: var timerRemoveButton = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "removeButton", userInfo: nil, repeats: true) var timerAddButton = NSTimer.schedul

我有两个NSTimer,我对它们进行了编程,使一个按钮出现在屏幕上,然后消失。我如何编程使其在满足条件后停止添加和删除按钮

这是我的密码:

   var timerRemoveButton = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "removeButton", userInfo: nil, repeats: true)
   var timerAddButton = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "addButton", userInfo: nil, repeats: true)

您可以像通常的Objective-C一样使其无效。因此,当您的条件满足时,只需写下:

timerRemoveButton.invalidate()
timerAddButton.invalidate()
这将从
nsrunlop
对象中删除计时器