0

I've watched this, but didn't found a solution.

I have a timer

self.checklinkTimer = [NSTimer scheduledTimerWithTimeInterval:5
                                                           target:self
                                                         selector:@selector(doWithHandler:)
                                                         userInfo:nil
                                                          repeats:YES];

and method

-(void) doWithHandler:(void (^)(BOOL isValid))handler
{
    handler(isSessionValid);
}   

and other method where i use boolean value from doWithHandler method.

In doWithHandler i need to check if handler is NSTimer class and in that case, not do handler(isSessionValid) .

I tried if ( ! [(id)handler isKindOfClass:[NSTimer class]] ) or @try @catch but this don't work this way.

Question: how can i check block class?

Community
  • 1
  • 1
Nike Kov
  • 12,630
  • 8
  • 75
  • 122

1 Answers1

0

you can don something like that instead of your original idea for achieving the same behaviour:

self.checklinkTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];

then you have:

- (void)timerFireMethod:(NSTimer *)timer {
    [self doWithHandler:nil];
}

where

- (void)doWithHandler:(void (^)(BOOL isValid))handler {
    if (handler) handler(isSessionValid); // I don't know where `isSessionValid` comes from...
}
holex
  • 23,961
  • 7
  • 62
  • 76