I want to call the function foo repeatedly but the nstimer isnt working.can you please help me?
@implementation abc
-(id)init
{
[NSTimer scheduledTimerWithTimeInterval:(1/16) target:self selector:@selector(foo) userInfo:nil repeats:YES];
}
This is my main
int main(int argc, char *argv[])
{
abc *ab=[[abc alloc]init];
[NSThread sleepForTimeInterval:100];
[ab release];
return 0;
}
It’s not working because
[NSTimer scheduledTimerWithTimeInterval:...](reference) states:… and you don’t have a run loop.
You can, for example, create an instance of
NSApplication(i.e. a proper Cocoa App) in order for this to work (you can probably create your own run loop without creating a Cocoa App, but it would be a fair amount of work).