When I use it like that the ns timer worksi.e its calling both foo1 and foo1
-(void)register1
{
NSRunLoop * runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(foo) userInfo:nil repeats:YES] forMode:NSDefaultRunLoopMode];
[runLoop addTimer:[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(foo2) userInfo:nil repeats:YES] forMode:NSDefaultRunLoopMode];
[runLoop run];
}
but my requirement is I have to use nstimer in different functions so that I can create an nsoperation of both.The code below only calls the first function.i.e when I call both register1 and register2 from main only 1 timer is registered.the top one
-(void)register1
{
NSRunLoop * runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(foo) userInfo:nil repeats:YES] forMode:NSDefaultRunLoopMode];
[runLoop run];
}
-(void)register2
{
NSRunLoop * runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(foo2) userInfo:nil repeats:YES] forMode:NSDefaultRunLoopMode];
[runLoop run];
}
I have found an answer to my question,thought I should tell others too.The solution is I had to use different threads for each function.I used nsoperation in main in this way
abc *ab=[[abc alloc]init];
//[ab register1];
// [ab register2];
NSOperationQueue *queue=[[NSOperationQueue alloc]init];
NSInvocationOperation *abc=[[NSInvocationOperation alloc]initWithTarget:ab selector:@selector(register1) object:(nil)];
NSInvocationOperation *abc2=[[NSInvocationOperation alloc]initWithTarget:ab selector:@selector(register2) object:(nil)];
[queue addOperation:abc];
[queue addOperation:abc2];