IOS - Creating & Using Interval Specific Timers

user879702 picture user879702 · Aug 10, 2011 · Viewed 18.4k times · Source

I am a newbie IOS developer, but I have a good amount of experience in Android development. My question is regarding the creating and use of interval specific timers.

In android I could easily make a timer like this:

timedTimer = new Timer();
    timedTimer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {

            TimedMethod();
        }

    }, 0, 1000);

Where the interval is 1000 MS and the method TimedMethod() is called on every tick. How would I go about implementing a similar function in IOS?

Thanks so much for reading! Any help at all would be great! :-)

Answer

Jacob Relkin picture Jacob Relkin · Aug 10, 2011

You can use a repeating NSTimer like so:

- (void) startTimer {
   [NSTimer scheduledTimerWithTimeInterval:1 
                                    target:self 
                                  selector:@selector(tick:) 
                                  userInfo:nil
                                   repeats:YES];
}

- (void) tick:(NSTimer *) timer {
   //do something here..

}