-
Notifications
You must be signed in to change notification settings - Fork 5
/
PWEventHandler.m
46 lines (39 loc) · 900 Bytes
/
PWEventHandler.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
//
// ProWidgets
//
// 1.0.0
//
// Created by Alan Yip on 18 Jan 2014
// Copyright 2014 Alan Yip. All rights reserved.
//
#import "header.h"
#import "PWEventHandler.h"
@implementation PWEventHandler
+ (instancetype)eventHandlerWithTarget:(id)target selector:(SEL)selector {
PWEventHandler *handler = [self new];
handler.target = target;
handler.selector = selector;
return [handler autorelease];
}
+ (instancetype)eventHandlerWithBlock:(void(^)(id))block {
PWEventHandler *handler = [self new];
handler.block = block;
return [handler autorelease];
}
- (void)triggerWithObject:(id)object {
if (_block != nil) {
_block(object);
} else {
if (_selector != NULL && [_target respondsToSelector:_selector]) {
[_target performSelector:_selector withObject:object];
}
}
}
- (void)dealloc {
DEALLOCLOG;
_target = nil;
_selector = NULL;
RELEASE(_block)
[super dealloc];
}
@end