You have NSTimer *timer;
declared alredy, so you need to add the following class method in the any AppDelegate Method, executing which you want to start the timer (Say for example -didFinishLaunchingWithOptions
)
timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self
selector:@selector(incrementVariable:)
userInfo:nil repeats:YES];
Also, you need to invalidate the timer wherever to want to stop it using:
[timer invalidate];
Now, say you have your Global variable variableName
which you want to increment every second. In order to do that, you have to implement the selector
you passed in scheduledTimerWithTimeInterval
method.
- (void)incrementVariable:(NSTimer *)timer{
variableName++;
}
Hope this helps.