forked from efroemling/bombsquad-remote-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSTimerUtils.m
27 lines (22 loc) · 976 Bytes
/
NSTimerUtils.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#import "NSTimerUtils.h"
typedef void (^PSYTimerBlock)(NSTimer *);
@interface NSTimer (UtilsPrivate)
+ (void)PSYBlockTimer_executeBlockWithTimer:(NSTimer *)timer;
@end
@implementation NSTimer (Utils)
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds repeats:(BOOL)repeats usingBlock:(void (^)())fireBlock
{
return [self scheduledTimerWithTimeInterval:seconds target:self selector:@selector(PSYBlockTimer_executeBlockWithTimer:) userInfo:[[fireBlock copy] autorelease] repeats:repeats];
}
+ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)seconds repeats:(BOOL)repeats usingBlock:(void (^)())fireBlock
{
return [self timerWithTimeInterval:seconds target:self selector:@selector(PSYBlockTimer_executeBlockWithTimer:) userInfo:[[fireBlock copy] autorelease] repeats:repeats];
}
@end
@implementation NSTimer (Utils_Private)
+ (void)PSYBlockTimer_executeBlockWithTimer:(NSTimer *)timer
{
PSYTimerBlock block = [timer userInfo];
block(timer);
}
@end