NStimer定时器的block回调

把平时常用的定时器封装成block形式,调用起来更加方便。
demo

代码:

typedef void (^MKTimerBlock) (void);

+ (NSTimer *)mk_scheduledTimerWithTimeInterval:(NSTimeInterval)interval repeats:(BOOL)repeats block:(MKTimerBlock)block{

   return  [self scheduledTimerWithTimeInterval:interval target:self selector:@selector(action:) userInfo:[block copy] repeats:repeats];

}

+ (void)action:(NSTimer *)userInfo{

   MKTimerBlock block = userInfo.userInfo;
    if (block) {
        block();
    }

}

你可能感兴趣的:(NStimer定时器的block回调)