I have a function, I'm trying to make it so every time it's called, it will invalidate an interval timer and make the interval faster. When I try to put an Int variable in the code for NSTimer.scheduledTimerWithTimeInterval, Xcode comes up with an error. I'm just starting swift and Xcode, so I'm very new to this. Thanks for the help.
All the variables are set before the function is active.
func makeIntervalFaster() {
timer.invalidate()
value++
var timerValue:Int = 1/value
timer = NSTimer.scheduledTimerWithTimeInterval(timerValue, target: self, selector: Selector("action"), userInfo: nil, repeats: true)
}
The interval should be a NSTimeInterval which is an alias for Double. Your argument is an Int.
So replace :Int
with :Double
and it should work. You'll probably have to convert value
to a Double as well. Swift doesn't like implicit conversions.