I should able to delay 2 seconds using NSTimer. How to do it?

Linux world picture Linux world · Sep 14, 2010 · Viewed 14.5k times · Source

I want to produce a delay of 2 seconds using NSTimer how to initialize timer in program?

Answer

davydotcom picture davydotcom · Sep 14, 2010

Multiple options here.

If you just want a delay of 2 seconds you could use the sleep() function

#include<unistd.h>
...
sleep(2);

Or you may be able to use NSTimer like so

[NSTimer    scheduledTimerWithTimeInterval:2.0    target:self    selector:@selector(fireMethod)    userInfo:nil repeats:NO];

And in your class you would have a method defined as

-(void)fireMethod
{
//Do stuff 
}