-
Notifications
You must be signed in to change notification settings - Fork 11
/
NSTimerUtils.m
38 lines (33 loc) · 1.34 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
#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