Can NSTimer use multiple selectors?

I am trying to use NSTimer

in my application and was wondering if two methods can be called when the timer fires.

Here's the code:

gameTimer = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector:
Selector("gameMovement" && "fireBullet"), userInfo: nil, repeats: true)

      

I am getting a message that there are two arguments in the selector.

+3


source to share


1 answer


Nope. You would only name one method that delegates whatever you want.

func someFunc() {
  gameTimer = NSTimer.scheduledTimerWithTimeInterval(
    0.01,
    target: self,
    selector: Selector("timerFired"),
    userInfo: nil,
    repeats: true
  )
}

func timerFired() {
  gameMovement()
  fireBullet()
}

      



This is a more user-friendly template anyway, as it is easier for you to see how your code flows.

+7


source







All Articles