-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathPHWeakTimerTarget.m
49 lines (33 loc) · 981 Bytes
/
PHWeakTimerTarget.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
39
40
41
42
43
44
45
46
47
48
49
/*
* Phoenix is released under the MIT License. Refer to https://github.com/kasper/phoenix/blob/master/LICENSE.md
*/
#import "PHWeakTimerTarget.h"
@interface PHWeakTimerTarget ()
@property(weak) id target;
@property SEL selector;
@end
@implementation PHWeakTimerTarget
#pragma mark - Initialising
- (instancetype)initWithTarget:(id)target selector:(SEL)selector {
if (self = [super init]) {
self.target = target;
self.selector = selector;
}
return self;
}
+ (instancetype)withTarget:(id)target selector:(SEL)selector {
return [[self alloc] initWithTarget:target selector:selector];
}
#pragma mark - Timing
- (void)timerDidFireProxy:(NSTimer *)timer {
// Target is still alive
if (self.target) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self.target performSelector:self.selector];
#pragma clang diagnostic pop
return;
}
[timer invalidate];
}
@end