-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSTimer+Block.m
executable file
·33 lines (25 loc) · 1.15 KB
/
NSTimer+Block.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
//
// NSTimer+Block.m
//
// Created by Marcus Brissman on 2014-12-05.
// Copyright (c) 2014 Marcus Brissman. All rights reserved.
//
#import "NSTimer+Block.h"
@implementation NSTimer (Block)
- (instancetype)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)seconds repeats:(BOOL)repeats block:(void (^)(void))block {
return [self initWithFireDate:date interval:seconds target:self.class selector:@selector(runBlock:) userInfo:block repeats:repeats];
}
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds repeats:(BOOL)repeats block:(void (^)(void))block {
return [self scheduledTimerWithTimeInterval:seconds target:self selector:@selector(runBlock:) userInfo:block repeats:repeats];
}
+ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)seconds repeats:(BOOL)repeats block:(void (^)(void))block {
return [self timerWithTimeInterval:seconds target:self selector:@selector(runBlock:) userInfo:block repeats:repeats];
}
#pragma mark - Private methods
+ (void)runBlock:(NSTimer *)timer {
if ([timer.userInfo isKindOfClass:NSClassFromString(@"NSBlock")]) {
void (^block)(void) = timer.userInfo;
block();
}
}
@end