Search code examples
multithreadingcocoa-touchnstimer

On what thread does a method initiated by NSTimer run on?


When method aMethod runs as a result of an NSTimer like so:

NSTimer* theTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0 
                                                     target: self 
                                                   selector: @selector(aMethod:) 
                                                   userInfo: nil
                                                    repeats: YES];

Does aMethod run on the thread where theTimer was called (the main thread), or on a separate thread? Also, does the NSTimer continue repeating while aMethod is running, or does it wait until aMethod has finished?


Solution

  • NSTimer calls the selector passed in the selector: parameter on the thread for which the timer was scheduled. This may or may not be the main thread.