BBATimer.h 9.65 KB
//
//  BBATimer
//  BBAPods
//
//  Created by 白昆仑 on 2017/8/2.
//  Copyright © 2017年 Baidu. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "BDPFoundationDefines.h"

/**
 * Timer相关的扩展,提供封装好的 block 定时器和 selector 定时器
 * 详细介绍请看README-BBATimer
 */

/*!
 @block
 @brief  定时器触发回调闭包
 @param  timer        定时器对象
 @param  target       目标对象(使用该对象可避免循环引用)
 @param  repeatTimes  设置的定时器触发总次数
 @param  repeatCount  定时器当前触发的次数
 @result 返回YES,继续定时器逻辑;NO,立即停止定时器
 */
typedef BOOL (^BBATimerBlock)(NSTimer *timer, id target, NSUInteger repeatTimes, NSUInteger repeatCount);

@interface NSTimer (BBABuilder)

#pragma mark - Block定时器

/*!
 @method
 @brief  创建一个NSTimer对象
 @param  interval     定时器触发时间间隔
 @param  isRepeat     是否重复触发定时
 @param  aTarget      目标对象,该对象会在block回调中回传,使用该对象可避免循环引用
 @param  block        回调函数
 @result NSTimer对象
 */
+ (instancetype)bba_timerWithTimeInterval:(NSTimeInterval)interval
                                  repeats:(BOOL)isRepeat
                                   target:(id)aTarget
                                    block:(BBATimerBlock)block BDP_FOUNDATION_DEPRECATED("please use  bdp_timerWithTimeInterval:repeats:target:block:");
+ (instancetype)bdp_timerWithTimeInterval:(NSTimeInterval)interval
                                  repeats:(BOOL)isRepeat
                                   target:(id)aTarget
                                    block:(BBATimerBlock)block;

/*!
 @method
 @brief  创建一个NSTimer对象
 @param  interval     定时器触发时间间隔
 @param  isRepeat     是否重复触发定时
 @patam  repeatTimes  定时器触发次数,设置为0表示不限制触发次数(该参数仅在isRepeat=YES下生效)
 @param  aTarget      目标对象,该对象会在block回调中回传,使用该对象可避免循环引用
 @param  block        回调函数
 @result NSTimer对象
 */
+ (instancetype)bba_timerWithTimeInterval:(NSTimeInterval)interval
                                  repeats:(BOOL)isRepeat
                              repeatTimes:(NSUInteger)repeatTimes
                                   target:(id)aTarget
                                    block:(BBATimerBlock)block BDP_FOUNDATION_DEPRECATED("please use  bdp_timerWithTimeInterval:repeats:repeatTimes:target:block:");
+ (instancetype)bdp_timerWithTimeInterval:(NSTimeInterval)interval
                                  repeats:(BOOL)isRepeat
                              repeatTimes:(NSUInteger)repeatTimes
                                   target:(id)aTarget
                                    block:(BBATimerBlock)block;

/*!
 @method
 @brief  创建一个NSTimer对象,并开启定时器
 @param  interval     定时器触发时间间隔
 @param  isRepeat     是否重复触发定时
 @param  aTarget      目标对象,该对象会在block回调中回传,使用该对象可避免循环引用
 @param  block        回调函数
 @result NSTimer对象
 */
+ (instancetype)bba_scheduleTimerWithTimeInterval:(NSTimeInterval)interval
                                          repeats:(BOOL)isRepeat
                                           target:(id)aTarget
                                            block:(BBATimerBlock)block BDP_FOUNDATION_DEPRECATED("please use  bdp_scheduleTimerWithTimeInterval:repeats:target:block:");
+ (instancetype)bdp_scheduleTimerWithTimeInterval:(NSTimeInterval)interval
                                          repeats:(BOOL)isRepeat
                                           target:(id)aTarget
                                            block:(BBATimerBlock)block;

/*!
 @method
 @brief  创建一个NSTimer对象,并开启定时器
 @param  interval     定时器触发时间间隔
 @param  isRepeat     是否重复触发定时
 @patam  repeatTimes  定时器触发次数,设置为0表示不限制触发次数(该参数仅在isRepeat=YES下生效)
 @param  aTarget      目标对象,该对象会在block回调中回传,使用该对象可避免循环引用
 @param  block        回调函数
 @result NSTimer对象
 */
+ (instancetype)bba_scheduleTimerWithTimeInterval:(NSTimeInterval)interval
                                          repeats:(BOOL)isRepeat
                                      repeatTimes:(NSUInteger)repeatTimes
                                           target:(id)aTarget
                                            block:(BBATimerBlock)block BDP_FOUNDATION_DEPRECATED("please use  bdp_scheduleTimerWithTimeInterval:repeats:repeatTimes:target:block:");
+ (instancetype)bdp_scheduleTimerWithTimeInterval:(NSTimeInterval)interval
                                          repeats:(BOOL)isRepeat
                                      repeatTimes:(NSUInteger)repeatTimes
                                           target:(id)aTarget
                                            block:(BBATimerBlock)block;

#pragma mark - Selector定时器

/*!
 @method
 @brief  创建一个NSTimer对象
 @param  interval     定时器触发时间间隔
 @param  isRepeat     是否重复触发定时
 @param  aTarget      目标对象,该对象会在block回调中回传,使用该对象可避免循环引用
 @param  aSelector    目标对象的调用方法
 @result NSTimer对象
 */
+ (instancetype)bba_timerWithTimeInterval:(NSTimeInterval)interval
                                  repeats:(BOOL)isRepeat
                                   target:(id)aTarget
                                 selector:(SEL)aSelector BDP_FOUNDATION_DEPRECATED("please use  bdp_timerWithTimeInterval:repeats:target:selector:");
+ (instancetype)bdp_timerWithTimeInterval:(NSTimeInterval)interval
                                  repeats:(BOOL)isRepeat
                                   target:(id)aTarget
                                 selector:(SEL)aSelector;

/*!
 @method
 @brief  创建一个NSTimer对象
 @param  interval     定时器触发时间间隔
 @param  isRepeat     是否重复触发定时
 @patam  repeatTimes  定时器触发次数,设置为0表示不限制触发次数(该参数仅在isRepeat=YES下生效)
 @param  aTarget      目标对象,该对象会在block回调中回传,使用该对象可避免循环引用
 @param  aSelector    目标对象的调用方法
 @param  userInfo     调用目标方法的回传参数
 @result NSTimer对象
 */
+ (instancetype)bba_timerWithTimeInterval:(NSTimeInterval)interval
                                  repeats:(BOOL)isRepeat
                              repeatTimes:(NSUInteger)repeatTimes
                                   target:(id)aTarget
                                 selector:(SEL)aSelector
                                 userInfo:(id)userInfo BDP_FOUNDATION_DEPRECATED("please use  bdp_timerWithTimeInterval:repeats:repeatTimes:target:selector:userInfo:");
+ (instancetype)bdp_timerWithTimeInterval:(NSTimeInterval)interval
                                  repeats:(BOOL)isRepeat
                              repeatTimes:(NSUInteger)repeatTimes
                                   target:(id)aTarget
                                 selector:(SEL)aSelector
                                 userInfo:(id)userInfo;

/*!
 @method
 @brief  创建一个NSTimer对象,并开启定时器
 @param  interval     定时器触发时间间隔
 @param  isRepeat     是否重复触发定时
 @param  aTarget      目标对象,该对象会在block回调中回传,使用该对象可避免循环引用
 @param  aSelector    目标对象的调用方法
 @result NSTimer对象
 */
+ (instancetype)bba_scheduleTimerWithTimeInterval:(NSTimeInterval)interval
                                          repeats:(BOOL)isRepeat
                                           target:(id)aTarget
                                         selector:(SEL)aSelector BDP_FOUNDATION_DEPRECATED("please use  bdp_scheduleTimerWithTimeInterval:repeats:target:selector:");
+ (instancetype)bdp_scheduleTimerWithTimeInterval:(NSTimeInterval)interval
                                          repeats:(BOOL)isRepeat
                                           target:(id)aTarget
                                         selector:(SEL)aSelector;

/*!
 @method
 @brief  创建一个NSTimer对象,并开启定时器
 @param  interval     定时器触发时间间隔
 @param  isRepeat     是否重复触发定时
 @patam  repeatTimes  定时器触发次数,设置为0表示不限制触发次数(该参数仅在isRepeat=YES下生效)
 @param  aTarget      目标对象,该对象会在block回调中回传,使用该对象可避免循环引用
 @param  aSelector    目标对象的调用方法
 @param  userInfo     调用目标方法的回传参数
 @result NSTimer对象
 */
+ (instancetype)bba_scheduleTimerWithTimeInterval:(NSTimeInterval)interval
                                          repeats:(BOOL)isRepeat
                                      repeatTimes:(NSUInteger)repeatTimes
                                           target:(id)aTarget
                                         selector:(SEL)aSelector
                                         userInfo:(id)userInfo BDP_FOUNDATION_DEPRECATED("please use  bdp_scheduleTimerWithTimeInterval:repeats:repeatTimes:target:selector:userInfo:");
+ (instancetype)bdp_scheduleTimerWithTimeInterval:(NSTimeInterval)interval
                                          repeats:(BOOL)isRepeat
                                      repeatTimes:(NSUInteger)repeatTimes
                                           target:(id)aTarget
                                         selector:(SEL)aSelector
                                         userInfo:(id)userInfo;

@end