NCoder
NCoder

Reputation: 335

Does NSTimer run across entire app?

If I start an NSTimer like this:

@property (strong) NSTimer * messageTimer;


self.messageTimer = [NSTimer scheduledTimerWithTimeInterval:10.0
                                     target:self
                                   selector:@selector(checkForMessages)
                                   userInfo:nil
                                    repeats:YES];

Does it continue to run when I switch to different view controllers?

Until I cancel it with:

[messageTimer invalidate]; self. messageTimer = nil; 

Upvotes: 0

Views: 127

Answers (1)

user2008074
user2008074

Reputation:

Yes.

Okay, now here is an extended description. NSTimer registers itself on nearest NSRunLoop, that is, current dispatch loop (they may nest). This loop asks various sources for events and calls corresponding callbacks.

When it is time for NSTimer to fire, it returns YES to NSRunLoop and that runs passed callback. There is no such thing as "other current view controller". It is all about first responder and view hierarchy, neither doesn't have any effect on run loops.

Upvotes: 1

Related Questions