-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNJHDelegateSplitter.m
More file actions
48 lines (36 loc) · 1.45 KB
/
NJHDelegateSplitter.m
File metadata and controls
48 lines (36 loc) · 1.45 KB
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
#import "NJHDelegateSplitter.h"
@implementation NJHDelegateSplitter
- (instancetype)initWithFirstDelegate:(id<NSObject>)firstDelegate secondDelegate:(id<NSObject>)secondDelegate {
if (self = [super init]){
_firstDelegate = firstDelegate;
_secondDelegate = secondDelegate;
}
return self;
}
- (void)forwardInvocation:(NSInvocation *)anInvocation {
SEL aSelector = [anInvocation selector];
if ([self.firstDelegate respondsToSelector:aSelector]) {
[anInvocation invokeWithTarget:self.firstDelegate];
}
if ([self.secondDelegate respondsToSelector:aSelector]) {
[anInvocation invokeWithTarget:self.secondDelegate];
}
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
NSMethodSignature *medthodSignature = nil;
if ([(NSObject *)self.firstDelegate methodSignatureForSelector:aSelector]) {
medthodSignature = [(NSObject *)self.firstDelegate methodSignatureForSelector:aSelector];
}
else if ([(NSObject *)self.secondDelegate methodSignatureForSelector:aSelector]) {
medthodSignature = [(NSObject *)self.secondDelegate methodSignatureForSelector:aSelector];
}
return medthodSignature;
}
- (BOOL)respondsToSelector:(SEL)aSelector {
BOOL respondsToSelector = NO;
if ([self.firstDelegate respondsToSelector:aSelector] || [self.secondDelegate respondsToSelector:aSelector]) {
respondsToSelector = YES;
}
return respondsToSelector;
}
@end