You're simply calling the parameters incorrectly to the scheduledTimerWithTimeInterval
method.
This API works in a very "old-fashioned" way: they don't take a closure but rather a target
object (on which to call the selector), and String-typed method selector.
The target
is usually just self
, e.g. the controller that you're working within that started the timer should also receive the timer events.
The selector
should be simply a hard-coded string: "handleTimer:"
so you have:
class MyController {
override func viewDidLoad() {
super.viewDidLoad()
/* Repeats every 10 seconds. handleTimer() can feel free to invalidate
and re-schedule this timer at a different interval */
NSTimer.scheduledTimerWithTimeInterval(10.0, self, "handleTimer:", nil, true)
}
func handleTimer(timer: NSTimer) {
/* Do my awesome GameKit stuff here, using stored properties to refer to
all my scene objects. (Since I don't get any params passed in) */
/* Now play with the timer any way I like, e.g.: */
let newInterval = timer.timeInterval + 1.0
timer.invalidate()
NSTimer.scheduledTimerWithTimeInterval(newInterval, self, "handleTimer:", nil, true)
}
}